Submission #1112007

#TimeUsernameProblemLanguageResultExecution timeMemory
1112007shfvbhwbrvjKnapsack (NOI18_knapsack)C++14
37 / 100
1065 ms504 KiB
#include <bits/stdc++.h>
using namespace std;

int s, n, maxv;
struct item_type {
    int v, w, k;
};
vector<item_type> item;
int dp[2001];
bool vis[2001];

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> s >> n;
    for (int i = 1; i <= n; i++) {
        int v, w, k;
        cin >> v >> w >> k;
        item_type temp;
        temp.v = v, temp.w = w, temp.k = k;
        item.push_back(temp);
    }

    vis[0] = true;
    for (auto i : item) {
        for (int j = 1; j <= i.k; j++) {
            for (int k = s; k >= i.w; k--) {
                if (vis[k - i.w]) {
                    dp[k] = max(dp[k], dp[k - i.w] + i.v);
                    maxv = max(maxv, dp[k]);
                    vis[k] = true;
                }
            }
        }
    }

    cout << maxv << endl;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...