Submission #716214

#TimeUsernameProblemLanguageResultExecution timeMemory
716214ToxtaqKnapsack (NOI18_knapsack)C++17
49 / 100
1078 ms96068 KiB
#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)

knapsack.cpp: In function 'long long int rec(int, int)':
knapsack.cpp:11:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     if(indx == weights.size() || W == 0)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...