| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 716214 | Toxtaq | Knapsack (NOI18_knapsack) | C++17 | 1078 ms | 96068 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;
struct Item{
int value, weight, quantity;
};
vector<int>weights, values;
//vector<vector<long long> >table;
map<pair<int, int>, long long>table;
long long rec(int indx, int W){
if(W < 0)return -1e18;
if(indx == weights.size() || W == 0)return 0;
if(table.count({indx, W}))return table[{indx, W}];
return table[{indx, W}] = max(rec(indx + 1, W - weights[indx]) + values[indx], rec(indx + 1, W));
}
int main()
{
int S, n;
cin >> S >> n;
vector<Item>items;
for(int i = 0;i < n;++i){
int v, w, q;
cin >> v >> w >> q;
q = min(q, S / w);
Item cur;
cur.value = v;
cur.weight = w;
cur.quantity = q;
items.push_back(cur);
}
for(int i = 0;i < n;++i){
int v = items[i].value, w = items[i].weight, q = items[i].quantity;
for(int j = 0;j < q;++j){
weights.push_back(w);
values.push_back(v);
}
}
// table.assign(S + 1, vector<long long>(weights.size(), -1));
cout << rec(0, 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... | ||||
