# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
955567 | haileyy | Knapsack (NOI18_knapsack) | C++14 | 1080 ms | 18980 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.
//https://oj.uz/problem/view/NOI18_knapsack
#include <bits/stdc++.h>
#define loop(i, l, r) for(int i = (l); i < (r); ++i)
#define pool(i, l, r) for(int i = (l); i > (r); --i)
#define debug(x) cerr << #x << ": " << x << endl;
using namespace std;
int n,s;
vector<pair<long long,long long>> items;
const int MAXS = 2005;//
long long dp[MAXS];
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>s>>n;
long long v,w,k;
loop(i,0,n){
cin>>v>>w>>k;
int a = log2(k);
loop(j,0,a){
items.push_back({(1<<j)*w,(1<<j)*v});
}
int b = k-(1<<a)+1;
items.push_back({b*w,b*v});
}
loop(i,0,items.size()){
pool(j,s,items[i].first-1){
dp[j] = max(dp[j],dp[j-items[i].first]+items[i].second);
}
}
cout<<dp[s]<<endl;
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... |