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>
#define nl '\n'
#define int long long
using namespace std;
struct item{
int value;
int weight;
int piece;
};
void solve(){
int s, n;
cin >> s >> n;
vector<item> v(n);
for(int i = 0; i < n; i++){
item tmp;
cin >> tmp.value >> tmp.weight >> tmp.piece;
v[i] = tmp;
}
vector< vector<int> > dp(n+1, vector<int>(s+1));
function<int(int, int)> f = [&](int i, int j){
if(i < 0 || j <= 0) return 0LL;
if(dp[i][j] != -1) return dp[i][j];
int t1 = 0;
if(j-v[i].weight >= 0) t1 = v[i].value + f(i, j-v[i].weight);
int t2 = 0;
if(i-1 >= 0) t2 = f(i-1, j);
return dp[i][j] = max(t1, t2);
};
cout << f(n-1, s) << nl;;
}
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0);
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... |