Submission #642425

#TimeUsernameProblemLanguageResultExecution timeMemory
642425burak_ozzkanKnapsack (NOI18_knapsack)C++14
17 / 100
4 ms1876 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); for(int i = 0; i < n; i++){ item tmp; cin >> tmp.value >> tmp.weight >> tmp.piece; v[i] = tmp; } vector< vector<int> > dp(n+1, vector<int>(s+1, -1)); function<int(int, int)> f = [&](int i, int j){ if(i < 0 || j <= 0) return 0LL; if(dp[i][j] != -1) return dp[i][j]; int t1 = 0; if(j-v[i].weight >= 0) t1 = v[i].value + f(i-1, j-v[i].weight); int t2 = 0; if(i-1 >= 0) t2 = f(i-1, j); return dp[i][j] = max(t1, t2); }; cout << f(n-1, s) << 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...