kamacoder-solutions icon indicating copy to clipboard operation
kamacoder-solutions copied to clipboard

faeture:Update 0057.爬楼梯.md C++题解

Open DIDA-lJ opened this issue 7 months ago • 0 comments

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

DIDA-lJ avatar Nov 23 '23 12:11 DIDA-lJ