結果

問題 No.357 品物の並び替え (Middle)
ユーザー Grun1396Grun1396
提出日時 2017-04-08 12:02:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 5,000 ms
コード長 875 bytes
コンパイル時間 479 ms
コンパイル使用メモリ 66,236 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-24 23:20:05
合計ジャッジ時間 1,394 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

const int MAX_N = 14;

int dp[1 << MAX_N] = {0};
int score_tbl[MAX_N][MAX_N] = {0};

int main(){
    int n,m;
    cin >> n >> m;

    int a,b,score,sub_total=0;
    for(int i = 0; i < m; i++){
        cin >> a >> b >> score;
        score_tbl[a][b] = score;
    }
   
    for(int i = 0; i < 1 << n; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++){
                if(((i >> j) & 1) && !((i >> k) & 1)){

                    for(int l = 0; l < n;l++){
                        if(i >> l & 1) sub_total += score_tbl[l][k];
                    }

                    dp[i | 1 << k] = max(dp[i | 1 << k],dp[i] + sub_total);

                    sub_total = 0;
                }
            }
        }
    }
    

    cout << dp[(1 << n)-1] << endl;
    return 0;
}
0