Submission #642420

#TimeUsernameProblemLanguageResultExecution timeMemory
642420burak_ozzkanKnapsack (NOI18_knapsack)C++14
0 / 100
1084 ms296 KiB
#include <bits/stdc++.h> #define nl '\n' // #define int long long using namespace std; struct item{ int value; int weight; int piece; }; void solve(){ int s, n; cin >> s >> n; vector<item> v(n); int max_k = -1; for(int i = 0; i < n; i++){ item tmp; cin >> tmp.value >> tmp.weight >> tmp.piece; v[i] = tmp; max_k = max(max_k, tmp.piece); } function<int(int, int, int)> f = [&](int i, int j, int k){ if(i < 0 || j <= 0 || k < 0) return 0; if(k == 0 && i > 0) return f(i-1, j, v[i-1].piece); int t1 = 0; if(j-v[i].weight >= 0) t1 = v[i].value + f(i, j-v[i].weight, k-1); int t2 = 0; if(i-1 >= 0) t2 = f(i-1, j, v[i-1].piece); return max(t1, t2); }; cout << f(n-1, s, v[n-1].piece) << nl;; } int32_t main(){ // ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; /*cin >> t;*/ while(t--) solve(); }
#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...