This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |