0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

##A問題
https://atcoder.jp/contests/abc129/tasks/abc129_a

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

p,q,r の内の2つを選び(3通り)合計の最小のものを選ぶ。

##B問題
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))

全探索します。リストの間ごとのiまでの合計、iからの合計の差を記録していき
最小値を出力する。

##C問題
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])

0段目は            1通り
1段目は0段目から1つ登りと言う  1通り
2段目は0段目から1通り
    1段目から1通り   合計2通り
3段目は1段目から  1通り
    2段目から 2通り  合計3通り

つまり n[i] = n[i-1]+n[i-2]
これを実装。
aに該当する場合は計算をスルー。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?