You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
617 B

1 year ago
#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int f[N]; // DP结果数组 f[i]含义第i层台阶共有多少种到达的方法数
int n, k;
/*
4 2
5
*/
int main() {
cin >> n >> k;
// 特判K=1
if (k == 1) {
cout << 1 << endl;
exit(0);
}
// 初始化 K>=2
f[1] = 1;
f[2] = 2;
// 状态转移方程
for (int i = 3; i <= n; i++)
for (int j = max(i - k, 1); j <= max(1, i - 1); j++)
f[i] += f[j];
// for (int i = 1; i <= n; i++) cout << f[i] << " ";
cout << f[n] << endl;
return 0;
}