제출 #827981

#제출 시각아이디문제언어결과실행 시간메모리
827981Kak008723Knapsack (NOI18_knapsack)C++14
37 / 100
1 ms468 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll V[100005],W[100005]; ll T,n,dp[100005]; int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>T>>n; int num=1; for(int i=1;i<=n;++i){ int v,w,s; cin>>v>>w>>s; for(int j=1;j<=s;j*=2){ V[num]=j*v; W[num]=j*w; num++; s-=j; } if(s){ V[num]=s*v; W[num]=s*w; num++; } } /*cout<<"\n"; for(int i=1;i<num;i++){ cout<<W[i]<<' '; }*/ for(int i=1;i<=num;i++){ for(int j=T;j-W[i]>=0;j--){ dp[j]=max(dp[j],dp[j-W[i]]+V[i]); } } cout<<dp[T]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...