結果

問題 No.2026 Yet Another Knapsack Problem
ユーザー suisensuisen
提出日時 2022-04-22 01:58:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,002 bytes
コンパイル時間 752 ms
コンパイル使用メモリ 83,460 KB
実行使用メモリ 56,520 KB
最終ジャッジ日時 2023-09-09 19:39:55
合計ジャッジ時間 21,970 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
56,520 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 6 ms
4,380 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 8 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 8 ms
4,380 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 5 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 6 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 692 ms
5,012 KB
testcase_29 AC 841 ms
5,124 KB
testcase_30 AC 841 ms
5,188 KB
testcase_31 AC 780 ms
5,152 KB
testcase_32 AC 659 ms
4,772 KB
testcase_33 AC 1,116 ms
5,352 KB
testcase_34 AC 954 ms
5,444 KB
testcase_35 AC 528 ms
4,772 KB
testcase_36 AC 759 ms
5,080 KB
testcase_37 AC 791 ms
5,012 KB
testcase_38 TLE -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// TLE Θ(N^4)

#include <algorithm>
#include <iostream>
#include <limits>
#include <vector>

constexpr int64_t inf = std::numeric_limits<int64_t>::max() / 2;

int main() {
    int n;
    std::cin >> n;

    std::vector<int32_t> c(n + 1);
    std::vector<int64_t> v(n + 1);
    for (int i = 1; i <= n; ++i) {
        std::cin >> c[i] >> v[i];
    }

    std::vector dp(n + 1, std::vector<int64_t>(n + 1, -inf));
    dp[0][0] = 0;

    for (int32_t i = 1; i <= n; ++i) {
        // dp[num][sum] = max{ pd[num-p][sum-p*i]+p*v[i] | 0<=p<=c[i] } ⋃ {-∞}
        for (int32_t num = n; num >= 0; --num) for (int32_t sum = n; sum >= 0; --sum) {
            for (int32_t p = 0; p <= c[i]; ++p) {
                if (p > num or p * i > sum) break;
                dp[num][sum] = std::max(dp[num][sum], dp[num - p][sum - p * i] + p * v[i]);
            }
        }
    }

    for (int32_t k = 1; k <= n; ++k) {
        std::cout << *std::max_element(dp[k].begin(), dp[k].end()) << '\n';
    }

    return 0;
}
0