Submission #965546

#TimeUsernameProblemLanguageResultExecution timeMemory
965546NourWaelKnapsack (NOI18_knapsack)C++17
73 / 100
477 ms3164 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int const mxN = 100; int dp[105][2005], cnt[105], n,w,k; pair<int,int> v[mxN]; int solve ( int i, int w) { if(i==n) return 0; if(~dp[i][w]) return dp[i][w]; int ans = solve(i+1, w); for(int c=1; c*v[i].second<=w && c<=cnt[i]; c++) { ans = max(ans, solve(i+1, w-c*v[i].second)+c*v[i].first); } return dp[i][w] = ans; } signed main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin>>w>>n; for(int i=0; i<n; i++) cin>>v[i].first>>v[i].second>>cnt[i]; memset(dp,-1,sizeof dp); cout<<solve(0,w)<<'\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...