結果

問題 No.527 ナップサック容量問題
ユーザー e869120
提出日時 2017-06-09 22:28:23
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 756 bytes
コンパイル時間 649 ms
コンパイル使用メモリ 79,264 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-22 15:09:30
合計ジャッジ時間 1,954 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
using namespace std;
int n, v[100], w[100], dp[102000], V;
int main() {
cin >> n; for (int j = 0; j < 102000; j++)dp[j] = -1e9;
dp[0] = 0;
for (int i = 0; i < n; i++) {
cin >> v[i] >> w[i];
for (int j = 100000; j >= 0; j--) {
if (dp[j] >= 0)dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
}
}
for (int i = 1; i <= 101999; i++)dp[i] = max(dp[i], dp[i - 1]);
cin >> V;
int minx = 1e9, maxn = -1e9;
for (int i = 1; i < 102000; i++) {
if (dp[i] == V) { minx = min(minx, i); maxn = max(maxn, i); }
}
if (maxn == 101999)cout << minx << endl << "inf" << endl;
else cout << minx << endl << maxn << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0