Files
python/TangDou/LanQiaoBei/ZhongGaoJi/LanQiao15STEMA202401/4.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

29 lines
617 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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