# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1064295 | vjudge1 | Knapsack (NOI18_knapsack) | C++17 | 3 ms | 1624 KiB |
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 endl '\n'
using namespace std;
int n,m;
int a[105];
int b[105];
int c[105];
int dp[105][100005];
int res[105];
main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// freopen("main.inp", "r", stdin);
// freopen("main.out", "w", stdout);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i] >> c[i];
}
for (int i = 1; i <= n; i++) {
dp[i][0] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
dp[i][j] = dp[i-1][j];
for (int k = 0; k <= min(c[i],j/a[i]); k++) {
if (dp[i-1][j-k*a[i]]+b[i]*k > dp[i][j]) {
//trace[i][j] = k;
dp[i][j] = dp[i-1][j-k*a[i]]+b[i]*k;
}
}
}
}
cout << dp[n][m];
}
Compilation message (stderr)
# | 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... |