题目1: 算法训练 K好数
解题思路
动态规划
代码
"""
1 2 3
0 1 3 8
1 1 2 5
2 1 2 5
3 1 3 8
"""
k, l = map(int, input().split())
mod = 1000000007
ans = 0
dp = [[0 for _ in range(l + 1)] for _ in range(k)]
for i in range(k):
dp[i][1] = 1
for i in range(2, l + 1): # 第 i 位
for j in range(k): # K 进制
for w in range(k):
if w != j - 1 and w != j + 1:
dp[j][i] = (dp[j][i] + dp[w][i - 1]) % mod
for i in range(1, k):
ans = (ans + dp[i][l]) % mod
print(ans)