# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1082901 | timmyli3481 | Knapsack (NOI18_knapsack) | C++14 | 1094 ms | 24968 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 "stdc++.h"
using namespace std;
struct grass{
long long v,w,c;
};
long long dp[2001];
grass a[100001*30];
int main(){
// ios::sync_with_stdio(false);
// cin.tie(0);
int T,m;
// cin>>T>>m;
scanf("%d%d",&T,&m);
int cnt=0;
for(int i=1;i<=m;i++){
long long v,w,c;
// cin>>v>>w>>c;
scanf("%lld%lld%lld",&v,&w,&c);
int t=1;
while(t<=c){
a[++cnt].v=v*t;
a[cnt].w=w*t;
c-=t;
t*=2;
}
if(c>0){
a[++cnt].v=v*c;
a[cnt].w=w*c;
}
}
for(int i=1;i<=cnt;i++){
for(int j=T;j>=a[i].w;j--){
dp[j]=max(dp[j],dp[j-a[i].w]+a[i].v);
}
}
cout<<dp[T];
}
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... |