# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
499074 | praxxus | Knapsack (NOI18_knapsack) | C++14 | 100 ms | 262148 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
using namespace std;
int main() {
int s, n;
cin >> s >> n;
vector<int> v;
vector<int> w;
for (int i=0; i<n; i++) {
int val, wei, quant;
cin >> val >> wei >> quant;
quant = min(quant, 2000/(wei+1));
for (int q=0; q<quant; q++) {
v.push_back(val);
w.push_back(wei);
}
}
vector<vector<int>> dp(v.size(), vector<int>(s+1, 0));
for (int i=0; i<=s; i++) if (w[0] <= i) dp[0][i] = v[0];
for (int i=1; i<v.size(); i++) {
for (int j=1; j<=s; j++) {
int a = 0;
if (j-w[i] >= 0) a = v[i] + dp[i-1][j-w[i]];
dp[i][j] = max(dp[i-1][j], a);
}
}
cout << dp[v.size()-1][s];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |