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
const int mod = 1e9 + 7;
const int N = 105;
int value[N], weight[N], amount[N];
int dp[N][2005];
int calc(int i, int cap) {
if (i == 0 or cap == 0)
return 0;
int &res = dp[i][cap];
if (res != -1) return res;
int temp = 0;
for (int k = 0; k <= amount[i]; k++)
if (k * weight[i] <= cap)
temp = max(temp, k * value[i] + calc(i - 1, cap - k * weight[i]));
return res = temp;
}
void test_case() {
int cap, n;
cin >> cap >> n;
for (int i = 1; i <= n; i++)
cin >> value[i] >> weight[i] >> amount[i];
memset(dp, -1, sizeof(dp));
int res = calc(n, cap);
cout << res << "\n";
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
test_case();
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... |