Submission #669818

#TimeUsernameProblemLanguageResultExecution timeMemory
669818GithubKnapsack (NOI18_knapsack)C++14
73 / 100
444 ms262144 KiB
#include <iostream> #include <vector> using namespace std; int main() { int n, s; cin >> s >> n; vector<int> value(n); vector<int> weight(n); vector<int> freq(n); for (int i = 0; i < n; i++){ cin >> value[i] >> weight[i] >> freq[i]; } int dp[s+1][n+1]; for (int i = 0; i <= n; i++){ for (int w = 0; w <= s; w++){ if ((i == 0) || (w == 0)){ dp[w][i] = 0; }else { dp[w][i] = 0; for (int r = 0; r <= freq[i-1]; r++){ if (r*weight[i-1] <= w){ dp[w][i] = max(dp[w][i], dp[w-weight[i-1]*r][i-1] + r*value[i-1]); }else{ r = freq[i-1]+1; } } } } } cout << dp[s][n] << endl; 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...