Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DIDA-lJ opened this issue Nov 23, 2023 · 0 comments
Open

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

DIDA-lJ opened this issue Nov 23, 2023 · 0 comments

Comments

@DIDA-lJ
Copy link
Contributor

DIDA-lJ commented Nov 23, 2023

#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;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant