# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1079031 | vjudge1 | Knapsack (NOI18_knapsack) | C++17 | 92 ms | 130564 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>
#include <map>
using namespace std;
#define fastIO ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr)
#define all(x) x.begin(),x.end()
#define take(x) for(int &el : x){ cin >> el;}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
const int MAX_N = 105;
const int MAX_K = 15;
const int MAX_S = 2005;
int n, S, k, tot_size;
ll v, w;
ll memo[MAX_N * MAX_K][MAX_S];
vector<ll> V, W;
ll dp(int id, ll remW) {
if(remW == 0 || id == tot_size || W[id] > remW){return 0;}
if(memo[id][remW] != -1){return memo[id][remW];}
return memo[id][remW] = max(V[id] + dp(id + 1, remW - W[id]), dp(id + 1, remW));
}
void solve(){
scanf("%d %d", &S, &n);
memset(memo, -1, sizeof memo);
V.clear();
W.clear();
for(int i = 0; i < n; i++) {
scanf("%lld %lld %d", &v, &w, &k);
for(int j = 0; j < k; j++) {
V.push_back(v);
W.push_back(w);
}
}
tot_size = (int)V.size();
ll ans = dp(0, S);
printf("%lld\n", ans);
}
int main(){
fastIO;
int tc = 1;
// scanf("%d", &tc);
while (tc--) {
solve();
}
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... |