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
/*--------------------------------------------------------------------------------------------------------------------------*/
int solvee(int i,int cap,int n,vector<vector<int>> &dp,vector<vector<int>> &v,int w){
if(i>=n)return 0;
if(dp[i][cap]!=-1)return dp[i][cap];
int nottake=solvee(i+1,cap,n,dp,v,w);
int take=0;
for(int k=1;k<=min(w,v[i][2]);k++){
if(k*v[i][1]<=cap)take=k*v[i][0]+solvee(i+1,cap-k*v[i][1],n,dp,v,w);
}
return dp[i][cap]=max(take,nottake);
}
void solve() {
int s,n;
cin >> s >> n;
vector<vector<int>> v(n);
for(int i=0;i<n;i++){
int x,y,z;
cin >> x >> y >> z;
v[i]={x,y,z};
}
vector<vector<int>> dp(n,vector<int> (s+1,-1));
cout<<solvee(0,s,n,dp,v,s)<<endl;
}
int32_t main() {
int t=1;
//cin >>t;
while(t--){
solve();
}
}
# | 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... |