Submission #1048189

#TimeUsernameProblemLanguageResultExecution timeMemory
1048189FCGVHBNKnapsack (NOI18_knapsack)C++14
49 / 100
1094 ms2396 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int memo(int index,int wei,int n,int s,vector<vector<int> >&info,vector<vector<int> >&dp){ if(index==n){ return 0; } if(dp[index][wei]!=-1){ return dp[index][wei]; } int nt=memo(index+1,wei,n,s,info,dp); int t=0; for(int i=0;i<info[index][2];i++){ if((i+1)*info[index][1]+wei<=s){ t=max(t,(i+1)*info[index][0]+memo(index+1,wei+(i+1)*info[index][1],n,s,info,dp)); } } return dp[index][wei]=max(t,nt); } signed main() { int s,n; cin>>s>>n; vector<vector<int> >info(n); for(int i=0;i<n;i++){ int v,w,k; cin>>v>>w>>k; info[i].push_back(v); info[i].push_back(w); info[i].push_back(k); } vector<vector<int> >dp(n,vector<int>(s+1,-1)); cout<<memo(0,0,n,s,info,dp)<<endl; }
#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...