HDU1028 - Ignatius and the Princess III

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

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

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

你可能感兴趣的:(HDU1028 - Ignatius and the Princess III)