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 int long long
#define F first
#define S second
#define T int t;cin>>t;while(t--)
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 1e5 + 6;
const int M = 2005;
const int mod = 1e9 + 7;
int dp[N][M];
int w[N], v[N], k[N], n, s;
int Rec(int i, int j) {
if (i > n) return 0;
int &ret = dp[i][j];
if (ret != -1) return ret;
for(int u = 0; u <= k[i]; u++) {
if (j + u * w[i] > s) break;
ret = max(ret, Rec(i + 1, j + u * w[i]) + u * v[i]);
}
return ret;
}
main() {
IOS
cin >> s >> n;
for(int i = 1; i <= n; i++)
cin >> v[i] >> w[i] >> k[i];
memset(dp, -1, sizeof dp);
cout << Rec(1, 0);
}
Compilation message (stderr)
knapsack.cpp:25:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
25 | main() {
| ^~~~
# | 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... |