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;
const int N = 100000;
const int S = 2000;
long long int v[N + 1], w[N + 1], k[N + 1], s, n, dp[N + 1][S + 1];
long long int f(int cur_ind, int cur_w){
if(cur_ind > n) return 0;
if(dp[cur_ind][cur_w] != -1) return dp[cur_ind][cur_w];
long long int a = 0;
for(long long int i = 0; i <= k[cur_ind]; i++){
if(cur_w + i*w[cur_ind] <= s){
a = max(a, f(cur_ind + 1, cur_w + i*w[cur_ind]) + v[cur_ind]*i);
}
else{
break;
}
}
return dp[cur_ind][cur_w] = a;
}
int main(){
cin >> s >> n;
for(int i = 1; i <= n; i++){
cin >> v[i] >> w[i] >> k[i];
for(int j = 0; j <= s; j++){
dp[i][j] = -1;
}
}
cout << f(1, 0);
return 0;
}
# | 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... |