結果
問題 |
No.527 ナップサック容量問題
|
ユーザー |
![]() |
提出日時 | 2018-03-13 18:25:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 40 ms / 2,000 ms |
コード長 | 1,252 bytes |
コンパイル時間 | 3,151 ms |
コンパイル使用メモリ | 167,200 KB |
実行使用メモリ | 46,524 KB |
最終ジャッジ日時 | 2024-11-22 11:47:52 |
合計ジャッジ時間 | 3,847 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define fst(t) std::get<0>(t) #define snd(t) std::get<1>(t) #define thd(t) std::get<2>(t) #define unless(p) if(!(p)) #define until(p) while(!(p)) using ll = long long; using P = std::tuple<int,int>; const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1}; int N, V; int vs[110], _ws[110]; int dp[110][100100]; int main(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cin >> N; for(int i=0;i<N;++i){ std::cin >> vs[i] >> _ws[i]; } std::cin >> V; fill(&dp[0][0], &dp[0][0]+110*100100, 1001001001); dp[0][0] = 0; for(int i=0;i<N;++i){ for(int j=0;j<=100000;++j){ dp[i+1][j] = min(dp[i+1][j], dp[i][j]); if(j + vs[i] <= 100000){ dp[i+1][j+vs[i]] = min(dp[i+1][j+vs[i]], dp[i][j] + _ws[i]); } } } int mn = max(dp[N][V], 1), mx = 1001001001; for(int i=V+1;i<=100000;++i){ if(dp[N][i] == 1001001001){continue;} mx = min(mx, dp[N][i] - 1); } std::cout << mn << std::endl; if(mx == 1001001001){ std::cout << "inf" << std::endl; }else{ std::cout << mx << std::endl; } }