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
vector<int> v, w , k;;
int dp[(int)1e5+2001][2001];
int knapsack(int i , int W){
if (i==0) return 0 ;
if (~dp[i][W]) return dp[i][W];
int b =0 ;
int a = knapsack(i-1 , W);
if (W >= w[i]) b = knapsack(i-1 , W-w[i]) + v[i];
return dp[i][W] = max(a , b);
}
signed main(){
memset(dp , -1 , sizeof dp);
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n , s ;
cin >> s >> n ;
v.resize(n+1) , w.resize(n+1) , k.resize(n+1);
for (int i = 1 ; i<=n ; i++){
cin >> v[i] >> w[i] >> k[i];
k[i] = min(s/w[i] , k[i]);
}
for (int i = 1 ; i<=n ; i++){
for (int j = 1 ; j<k[i] ; j++){
w.push_back(w[i]); v.push_back(v[i]);
}
}
n = v.size();
cout << knapsack(n , s);
}
# | 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... |