結果

問題 No.357 品物の並び替え (Middle)
ユーザー tsutajtsutaj
提出日時 2019-06-23 22:55:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 643 bytes
コンパイル時間 495 ms
コンパイル使用メモリ 66,580 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 14:06:20
合計ジャッジ時間 1,400 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 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 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 9 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 31 ms
4,376 KB
testcase_13 AC 15 ms
4,380 KB
testcase_14 AC 11 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 6 ms
4,376 KB
testcase_17 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

int dp[1 << 14], u[210], v[210], c[210];
int main() {
    int N, M; cin >> N >> M;
    for(int i=0; i<M; i++) cin >> u[i] >> v[i] >> c[i];
    
    for(int bit=0; bit<(1<<N); bit++) {
        for(int i=0; i<N; i++) {
            if(bit >> i & 1) continue;
            int nbit = bit | (1 << i);
            int add = 0;
            for(int k=0; k<M; k++) {
                if(!(bit >> u[k] & 1) or v[k] != i) continue;
                add += c[k];
            }
            dp[nbit] = max(dp[nbit], dp[bit] + add);
        }
    }
    cout << dp[(1<<N)-1] << endl;
    return 0;
}
0