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.
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.
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