Submission #976733

#TimeUsernameProblemLanguageResultExecution timeMemory
976733vjudge1Knapsack (NOI18_knapsack)C++17
0 / 100
112 ms262144 KiB
#include <bits/stdc++.h> using namespace std; #define debug cout << "here\n"; #define ll long long long long ans = 0; ll v[1000003], w[1000003],k[1000003]; ll dp[2002][100003]; long long ns(int s, int idx){ if(s==0 || idx == 0)return 0; else if(dp[s][idx] != -1) return dp[s][idx]; ll res = 0; for(int i = 1; i <= k[idx]; i++){ if(s >= w[idx] * i) res = max(res, ns(s-w[idx] * i, idx-1) + v[idx] * i); else break; } res = max(res, ns(s,idx-1)); dp[s][idx] = res; return res; } int main() { memset(dp,-1,sizeof(dp)); int s,n; cin >> s>> n; for(int i = 1; i <= n; i++) cin >> v[i] >> w[i] >> k[i]; cout << ns(s,n); 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...