# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
618109 | Nafeeszx | Knapsack (NOI18_knapsack) | C++17 | 543 ms | 262144 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>
using namespace std;
#define trav(a, x) for(auto& a : x)
#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define ROF(i, a, b) for (int i=(a); i>=(signed)(b); i--)
#define F0R(i, a) for (int i=0; i<(signed)(a); i++)
#define vi vector<int>
#define vvl vector<vector<ll>>
#define all(v) (v).begin(),(v).end()
typedef long long ll;
void setIO(string name = "") {
ios_base::sync_with_stdio(0); cin.tie(0);
if(name.size()){
freopen((name+".in").c_str(), "r", stdin);
freopen((name+".out").c_str(), "w", stdout);
}
}
const int mod = 1e9 + 7, MOD = 998244353;
int dp[100000][2001];
int main()
{
setIO();
int s, n;
cin >> s >> n;
vector<int> v(n), w(n), k(n);
F0R(i, n) cin >> v[i] >> w[i] >> k[i];
for(int t = 0; t * w[0] <= s && t <= k[0]; ++t) dp[0][t*w[0]] = t * v[0];
F0R(i, n-1) {
FOR(j, 0, s) {
for(int t = 0; j + t * w[i+1] <= s && t <= k[i+1]; ++t) {
dp[i+1][j+t*w[i+1]] = max(dp[i+1][j+t*w[i+1]], dp[i][j] + t * v[i+1]);
}
}
}
int res = 0;
//for(int j = 0; j < n; ++j) {
for(int i = 0; i <= s; ++i) {
res = max(res, dp[n-1][i]);
//cout << dp[j][i] << " ";
}
//cout << "\n";
//}
cout << res;
//cout << dp[0][12];
return 0;
}
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... |