Submission #693347

#TimeUsernameProblemLanguageResultExecution timeMemory
693347hanluluKnapsack (NOI18_knapsack)C++14
73 / 100
224 ms262144 KiB
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9+7; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //freopen("snakes.in","r",stdin); //freopen("snakes.out","w",stdout); int s,n; cin >> s >> n; vector<int> v(n+1),w(n+1),k(n+1); for (int i = 1; i<=n; i++) { cin >> v[i] >> w[i] >> k[i]; k[i] = min(k[i],s/w[i]); } vector< vector<int> > dp(n+1,vector<int>(s+1,0)); for (int i = 1; i <= n; i++) for (int j = 1; j <= s; j++) { for (int c = 0; c <= k[i] && c*w[i] <= j;c++) { //选c个物品i dp[i][j] = max(dp[i][j], dp[i-1][j- c*w[i]] + c*v[i]); } } cout << dp[n][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...