ABC129 A, B, C commentary

A problem

https://atcoder.jp/contests/abc129/tasks/abc129_a

p,q,r = map(int,input().split())
print(min(p+q,q+r,p+r))

Select two of p, q, r (three ways) and select the one with the smallest total.

B problem

https://atcoder.jp/contests/abc129/tasks/abc129_b

n = int(input())
w = list(map(int,input().split()))
ans = []
for i in range(1,n):
    ans.append(abs(sum(w[:i])-sum(w[i:])))
print(min(ans))

Search all. Record the difference between the totals up to i and the totals from i for each list. Output the minimum value.

C problem

https://atcoder.jp/contests/abc129/tasks/abc129_c

n,m = map(int,input().split())
a = set([int(input())for _ in range(m)])
dp = [0]*(n+1)
dp[0] = 1
if 1 in a :
    dp[1] = 0
else:
    dp[1] = 1
 
for i in range(2,n+1):
    if i in a:
        continue
    dp[i] = (dp[i-1]+dp[i-2])%1000000007
print(dp[n])

The 0th stage is 1 way The first step is said to climb one step from the 0th step. The second stage is one way from the 0th stage 1 way from the 1st stage, 2 ways in total The 3rd stage is 1 way from the 1st stage 2 ways from the 2nd stage, 3 ways in total

In other words, n [i] = n [i-1] + n [i-2] Implement this. If it corresponds to a, the calculation is skipped.

Recommended Posts

ABC129 A, B, C commentary
ABC128 A, B, C commentary (python)
ABC127 A, B, C Explanation (python)
ABC126 A, B, C Explanation (python)
Solve ABC175 A, B, C in Python
Solve Atcoder ABC176 (A, B, C, E) in Python
Solve ABC163 A ~ C with Python
ABC166 in Python A ~ C problem
Solve ABC168 A ~ C with Python
Solve ABC036 A ~ C in Python
Solve ABC162 A ~ C with Python
Solve ABC167 A ~ C with Python
Solve ABC158 A ~ C with Python
Solve ABC037 A ~ C in Python
[AtCoder explanation] Control ABC180 A, B, C problems with Python!
[AtCoder explanation] Control ABC188 A, B, C problems with Python!
[AtCoder explanation] Control ABC158 A, B, C problems with Python!
[AtCoder explanation] Control ABC164 A, B, C problems with Python!
[AtCoder explanation] Control ABC168 A, B, C problems with Python!
python> keyword arguments> hoge (** {'a': 1,'b': 2,'c': 3})
Solve ABC165 A, B, D in Python
[AtCoder explanation] Control the A, B, C problems of ABC182 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC186 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC185 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC187 with Python!
[AtCoder explanation] Control the A, B, C problems of ABC184 with Python!
Challenge AtCoder (ABC) 164 with Python! A ~ C problem
[AtCoder explanation] Control the A, B, C, D problems of ABC183 with Python!
ABC147 C --HonestOrUnkind2 [Python]
Python3> round (a --b, 7)
[AtCoder explanation] Control the A, B, C, D problems of ABC181 with Python!
There are two interpretations of VBScript a = b = c
ABC163 C problem with python3
AtCoder ABC 178 Python (A ~ E)
ABC memorandum [ABC163 C --managementr] (Python)
AtCoder ABC 176 Python (A ~ E)
AtCoder ABC 182 Python (A ~ D)
ABC188 C problem with python3
ABC187 C problem with python
Python a + = b and a = a + b are different
I made a C ++ learning site
ABC memorandum [ABC159 C --Maximum Volume] (Python)
Write a table-driven test in C
To add a C module to MicroPython ...
Solve ABC166 A ~ D with Python
Atcoder ABC125 C --GCD on Blackboard
Make C compilation a little easier
ABC memorandum [ABC161 C --Replacing Integer] (Python)
ABC memorandum [ABC158 C --Tax Increase] (Python)
Solved AtCoder ABC 114 C-755 with Python3
Template AtCoder ABC 179 Python (A ~ E)
[Python] return A [or / and] B
C> Enter a number> fgets () / sscanf ()
Create a C wrapper using Boost.Python
What happens if you do "import A, B as C" in Python?