atcoder 競プロ典型90問 050 - Stair Jump(★3)
2022.12.13
問題
方針
- dp
- 条件分岐だけ注意
i-l
が0以上なら、dp[i] = dp[i-1] + dp[i-l]
i-l
が0未満なら、dp[i] = dp[i-1]
pythonn, l = map(int, input().split()) dp = [0 for _ in range(n + 1)] dp[0] = 1 dp[1] = 1 for i in range(2, n + 1): if i - l >= 0: dp[i] = dp[i-1] + dp[i-l] else: dp[i] = dp[i-1] print(dp[n] % (pow(10, 9) + 7))