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

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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;
}