結果
問題 |
No.527 ナップサック容量問題
|
ユーザー |
|
提出日時 | 2018-07-08 07:37:27 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 13 ms / 2,000 ms |
コード長 | 363 bytes |
コンパイル時間 | 520 ms |
コンパイル使用メモリ | 67,252 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-06 14:22:54 |
合計ジャッジ時間 | 1,947 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
コンパイルメッセージ
main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 6 | main() | ^~~~
ソースコード
#include<iostream> #include<algorithm> using namespace std; int dp[1<<17]; int n; main() { cin>>n; for(int i=0;i<n;i++) { int v,w;cin>>v>>w; for(int j=1<<17;j-->w;) { dp[j]=max(dp[j],dp[j-w]+v); } } int v; cin>>v; int l=1; while(dp[l]<v)l++; cout<<l<<endl; while(dp[l]==v&&l<1<<17)l++; if(l<1<<17)cout<<l-1<<endl; else cout<<"inf"<<endl; }