結果

問題 No.733 分身並列コーディング
ユーザー りあんりあん
提出日時 2017-08-25 05:58:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 1,500 ms
コード長 862 bytes
コンパイル時間 2,751 ms
コンパイル使用メモリ 169,024 KB
実行使用メモリ 13,824 KB
最終ジャッジ日時 2024-05-03 22:32:26
合計ジャッジ時間 4,093 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 43 ms
13,696 KB
testcase_04 AC 43 ms
13,568 KB
testcase_05 AC 45 ms
13,696 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 44 ms
13,696 KB
testcase_08 AC 45 ms
13,696 KB
testcase_09 AC 20 ms
8,576 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 11 ms
6,016 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 AC 20 ms
8,448 KB
testcase_20 AC 22 ms
8,576 KB
testcase_21 AC 11 ms
5,888 KB
testcase_22 AC 44 ms
13,696 KB
testcase_23 AC 11 ms
5,888 KB
testcase_24 AC 11 ms
6,016 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 44 ms
13,568 KB
testcase_29 AC 44 ms
13,696 KB
testcase_30 AC 44 ms
13,696 KB
testcase_31 AC 44 ms
13,568 KB
testcase_32 AC 6 ms
5,376 KB
testcase_33 AC 7 ms
5,376 KB
testcase_34 AC 6 ms
5,376 KB
testcase_35 AC 6 ms
5,376 KB
testcase_36 AC 6 ms
5,376 KB
testcase_37 AC 7 ms
5,376 KB
testcase_38 AC 44 ms
13,696 KB
testcase_39 AC 45 ms
13,696 KB
testcase_40 AC 44 ms
13,696 KB
testcase_41 AC 6 ms
5,376 KB
testcase_42 AC 6 ms
5,376 KB
testcase_43 AC 6 ms
5,376 KB
testcase_44 AC 44 ms
13,824 KB
testcase_45 AC 44 ms
13,696 KB
testcase_46 AC 44 ms
13,696 KB
testcase_47 AC 44 ms
13,696 KB
testcase_48 AC 44 ms
13,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int dp[1 << 18][20];
const int M = 1000000007;

int main()
{
    // O(N^2 2^N)
    int c, n;
    cin >> c >> n;
    vector<int> w(n);
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
    }
    for (int i = 1; i < (1 << n); ++i)
        for (int j = 0; j <= n; ++j)
            dp[i][j] = M;

    for (int i = 1; i < (1 << n); ++i) {
        for (int j = 0; j < n; ++j) {
            if ((i >> j) & 1) {
                for (int k = 0; k <= n; ++k) {
                    dp[i][k] = min(dp[i][k], dp[i ^ (1 << j)][k] + w[j]);
                    if (dp[i][k] <= c)
                        dp[i][k + 1] = 0;
                }
            }
        }
    }
    for (int i = 0; i <= n; ++i) {
        if (!dp[(1 << n) - 1][i]) {
            cout << i << "\n";
            return 0;
        }
    }

    return 0;
}
0