結果

問題 No.90 品物の並び替え
ユーザー t-0gat-0ga
提出日時 2019-07-12 13:31:54
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 600 bytes
コンパイル時間 1,376 ms
コンパイル使用メモリ 144,712 KB
実行使用メモリ 4,512 KB
最終ジャッジ日時 2023-08-11 00:02:24
合計ジャッジ時間 1,722 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
int main()
{
    int N, M;
    cin >> N >> M;
    int table[N][N];
    int dp[1<<N];
    
    for(int i = 0 ; i < M ; ++i)
    {
        int i1, i2, sc;
        cin >> i1 >> i2 >> sc;
        table[i1][i2] = sc;
    }
    for(int i = 0 ; i < (1<<N) ; ++i)for(int j = 0 ; j < N ; ++j )
    {
        if(i &(1<<j)) continue;
        int sc = dp[i];
        for(int k = 0 ; k < N ; ++k)
        {
            if(i & (1<<k)) sc += table[k][j];
        }
        dp[i | (1<<j)] = max(dp[i|(1<<j)], sc);
    }
    cout << dp[(1<<N) -1] << endl;
    return 0;
}
0