# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
768948 | xgon6576 | Knapsack (NOI18_knapsack) | C++14 | 143 ms | 262144 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 <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int s, n;
cin >> s >> n;
vector<int> v;
vector<int> w;
v.push_back(0);
w.push_back(0);
for (int i = 0; i < n; i++) {
int a, b, c;
cin >> a >> b >> c;
for (int j = 0; j < min(c, (s/b)+1); j++) {
v.push_back(a);
w.push_back(b);
}
}
vector<vector<int>> dp(v.size()+1, vector<int>(s+1, 0));
for (int i = 1; i <= v.size(); i++) {
for (int j = 0; j <= s; j++) {
dp[i][j] = dp[i-1][j];
if (w[i] <= j) dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i]);
}
}
cout << dp[v.size()][s] << endl;
return 0;
}
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... |