HDU1028 - Ignatius and the Princess III

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1028

这是道完全背包问题,一共有N个数,且每个数可重复。

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n = 120;
    int dp[121] = {1};
    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j++) {
            dp[j] += dp[j-i];
        }
    }
    while (cin >> n) {
        cout << dp[n] << endl;
    }
    return 0;
}
posted @ 2019-12-15 13:05  oeong  阅读(104)  评论(0编辑  收藏