結果
問題 | No.527 ナップサック容量問題 |
ユーザー | hotpepsi |
提出日時 | 2017-06-13 00:03:35 |
言語 | C++11 (gcc 11.4.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 922 bytes |
コンパイル時間 | 480 ms |
コンパイル使用メモリ | 59,928 KB |
実行使用メモリ | 8,068 KB |
最終ジャッジ日時 | 2023-10-24 21:40:04 |
合計ジャッジ時間 | 4,038 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | AC | 3 ms
4,348 KB |
testcase_04 | AC | 2 ms
4,348 KB |
testcase_05 | TLE | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
ソースコード
#include <iostream> #include <sstream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; int main(int argc, char *argv[]) { int n, v[100], w[100], sum = 0, mv; cin >> n; for (int i = 0; i < n; ++i) { cin >> v[i] >> w[i]; sum += w[i]; } cin >> mv; int dp[100001]; memset(dp, -1, sizeof(dp)); int low = -1, high = 0; for (int t = 1; t <= sum; ++t) { memset(dp, -1, (t + 1) * sizeof(int)); dp[0] = 0; int z = 0; for (int i = 0; i < n; ++i) { for (int j = t; j >= w[i]; --j) { int k = dp[j - w[i]]; if (k >= 0) { dp[j] = max(dp[j], k + v[i]); } } } int mm = 0; for (int i = 0; i <= t; ++i) { mm = max(mm, dp[i]); } if (mm == mv) { if (low < 0) { low = t; } high = t; } else if (mm > mv) { break; } } cout << low << endl; if (high == sum) { cout << "inf" << endl; } else { cout << high << endl; } return 0; }