Submission #876184

#TimeUsernameProblemLanguageResultExecution timeMemory
876184CBG6682Knapsack (NOI18_knapsack)C++14
0 / 100
9 ms10588 KiB
#include <bits/stdc++.h> using namespace std; const int MAXX = 1e5 + 5; int s,n,dp[2001][MAXX]; struct Product{ int v,w,k; }; Product product[MAXX]; bool cmp(Product a, Product b){ return a.w < b.w; } int minn = 1e9; int main(){ cin >> s >> n; for (int i = 0; i < n; i++){ cin >> product[i].v >> product[i].w >> product[i].k; minn = min(product[i].w,minn); } sort(product,product + n,cmp); for (int i = 1; i <= s; i += minn){ for (int j = 0; j < n; j++){ if (i >= product[j].w){ int num = 1; dp[i][j] = max(dp[i - 1][j],dp[i][j - 1]); while (num*product[j].w <= i && num <= product[j].k){ dp[i][j] = max(dp[(i - num*product[j].w - 1)/minn*minn + 1][j - 1] + product[j].v*num,dp[i][j]); num++; } } } } cout << dp[s][n - 1]; 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...