結果
問題 | No.626 Randomized 01 Knapsack |
ユーザー | ミドリムシ |
提出日時 | 2017-12-15 21:48:36 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,151 bytes |
コンパイル時間 | 862 ms |
コンパイル使用メモリ | 76,552 KB |
実行使用メモリ | 277,392 KB |
最終ジャッジ日時 | 2024-05-09 08:03:44 |
合計ジャッジ時間 | 8,182 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 68 ms
276,852 KB |
testcase_01 | AC | 67 ms
276,852 KB |
testcase_02 | AC | 67 ms
276,896 KB |
testcase_03 | AC | 68 ms
276,860 KB |
testcase_04 | AC | 70 ms
276,884 KB |
testcase_05 | AC | 67 ms
276,944 KB |
testcase_06 | AC | 95 ms
276,740 KB |
testcase_07 | AC | 96 ms
276,972 KB |
testcase_08 | AC | 124 ms
276,804 KB |
testcase_09 | AC | 122 ms
276,936 KB |
testcase_10 | AC | 243 ms
277,076 KB |
testcase_11 | AC | 458 ms
277,136 KB |
testcase_12 | AC | 567 ms
277,164 KB |
testcase_13 | WA | - |
testcase_14 | AC | 175 ms
277,136 KB |
testcase_15 | WA | - |
testcase_16 | AC | 536 ms
277,232 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 74 ms
277,256 KB |
testcase_22 | AC | 348 ms
277,208 KB |
testcase_23 | AC | 527 ms
277,212 KB |
testcase_24 | AC | 70 ms
277,200 KB |
ソースコード
#include <iostream> #include <algorithm> #include <vector> using namespace std; struct item{ long value, weight; }; int n; long W; vector<item> items; long dp[5000][7000]; long mod_number; bool compare(item item1, item item2){ return item1.weight > item2.weight; } long pack(int now, long weight_now){ if(now == n){ return 0; }else if(dp[now][weight_now / mod_number] != -1){ return dp[now][weight_now / mod_number]; }else{ if(weight_now + items[now].weight > W){ return dp[now][weight_now / mod_number] = pack(now + 1, weight_now); }else{ return dp[now][weight_now / mod_number] = max(pack(now + 1, weight_now), items[now].value + pack(now + 1, weight_now + items[now].weight)); } } } int main(){ cin >> n >> W; items.resize(n); for(int i = 0; i < n; i++){ cin >> items[i].value >> items[i].weight; } sort(items.begin(), items.end(), &compare); for(int i = 0; i < 5000; i++){ for(int j = 0; j < 7000; j++){ dp[i][j] = -1; } } mod_number = W / 7000 + 1; cout << pack(0, 0) << endl; }