kamacoder-solutions
kamacoder-solutions copied to clipboard
faeture:Update 0057.爬楼梯.md C++题解
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main() {
int n, m;
while (cin >> n >> m) {
vector<int> dp(n + 1, 0);
dp[0] = 1;
for (int i = 1; i <= n; i++) { // 遍历物品
for (int j = 1; j <= m; j++) { // 遍历背包
if (i - j >= 0) dp[i] += dp[i - j];
}
}
cout << dp[n] << endl;
}
}