Submission #975408

#TimeUsernameProblemLanguageResultExecution timeMemory
975408vjudge1Knapsack (NOI18_knapsack)C++98
17 / 100
1 ms1208 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int s,n; cin>>s>>n; int w[n+1],v[n+1]; for (int i = 1; i <= n; i++) { int tk; cin>>v[i]>>w[i]>>tk; } int dp[n+1][s+1]; for (int i = 0; i <= s; i++) { dp[0][i]=0; } for (int i = 0; i <= n; i++) { dp[i][0]=0; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= s; j++) { if(w[i]>j){ dp[i][j]=dp[i-1][j]; }else{ dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]); } } } cout<<dp[n][s]; }
#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...