제출 #920533

#제출 시각아이디문제언어결과실행 시간메모리
920533AndrijaMKnapsack (NOI18_knapsack)C++14
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; long long s,n; vector<pair<long long,pair<long long,long long>>>x; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>s>>n; long long dp[s+1]; long long D[s+1]; memset(dp,0,sizeof dp); for(long long i=0;i<n;i++) { long long v,w,k; cin>>v>>w>>k; x.push_back({v,{w,k}}); } long long ans=0; for(long long i=0;i<n;i++) { for(int idx=0;idx<s+1;idx++) { D[idx]=dp[idx]; } for(long long j=min(s,x[i].second.second);j>=1;j--) { if(s-j*x[i].second.first<=0)break; for(long long p=s;p>=j*x[i].second.first;p--) { dp[p]=max(max(D[p],dp[p]),D[p-j*x[i].second.first]+j*x[i].first); } ///cout<<i<<" "<<j<<" "<<dp[20]<<endl; } } cout<<dp[s]<<endl; }

컴파일 시 표준 에러 (stderr) 메시지

knapsack.cpp: In function 'int main()':
knapsack.cpp:21:15: warning: unused variable 'ans' [-Wunused-variable]
   21 |     long long ans=0;
      |               ^~~
#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...