結果

問題 No.27 板の準備
ユーザー ふーらくたるふーらくたる
提出日時 2016-07-06 02:25:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,015 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 52,596 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 04:30:02
合計ジャッジ時間 1,287 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

const int kINF = 1 << 28;
const int kMAX_LEN = 32;

int v0, v1, v2, v3;
int length[3], dp[kMAX_LEN];

int Knapsack() {
    fill(dp, dp + kMAX_LEN, kINF);
    dp[0] = 0;
    for (int i = 0; i < 3; i++) {
        for (int len = 0; len < kMAX_LEN; len++) {
            if (len - length[i] >= 0) {
                dp[len] = min(dp[len], dp[len - length[i]] + 1);
            }
        }
    }
    return dp[v0] + dp[v1] + dp[v2] + dp[v3];
}

void Solve() {
    int answer = kMAX_LEN;
    for (int a = 1; a <= kMAX_LEN; a++) {
        for (int b = a + 1; b <= kMAX_LEN; b++) {
            for (int c = b + 1; c <= kMAX_LEN; c++) {
                length[0] = a;
                length[1] = b;
                length[2] = c;

                // ここで個数制限なしナップザック
                answer = min(answer, Knapsack());
            }
        }
    }
    cout << answer << endl;
}

int main() {
    cin >> v0 >> v1 >> v2 >> v3;

    Solve();

    return 0;
}
0