以下の内容はhttps://suikaba.hatenablog.com/entry/2017/07/02/234925より取得しました。


Typical DP Contest A - コンテスト

解法

基本的なナップサック問題
p(i), N <= 100 なので,高々 10^6 のループで終わる.

ソースコード

#include <bits/stdc++.h>
using namespace std;

constexpr int max_p = 10000;

int main() {
    int n; cin >> n;
    vector<int> p(n);
    for(auto& x : p) cin >> x;

    vector<bool> dp(max_p + 1);
    dp[0] = true;
    for(int i = 0; i < n; ++i) {
        for(int j = max_p - p[i]; j >= 0; --j) {
            dp[j + p[i]] = dp[j + p[i]] | dp[j];
        }
    }

    cout << count(dp.begin(), dp.end(), true) << endl;
}



以上の内容はhttps://suikaba.hatenablog.com/entry/2017/07/02/234925より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14