結果

問題 No.357 品物の並び替え (Middle)
ユーザー kimiyukikimiyuki
提出日時 2016-06-08 05:12:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 693 bytes
コンパイル時間 744 ms
コンパイル使用メモリ 72,180 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 08:28:22
合計ジャッジ時間 1,354 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 8 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
template <class T> bool setmax(T & l, T const & r) { if (not (l < r)) return false; l = r; return true; }
using namespace std;
int main() {
    int n, m; cin >> n >> m;
    vector<vector<int> > score(n, vector<int>(n));
    repeat (i,m) {
        int x, y, z; cin >> x >> y >> z;
        score[x][y] = z;
    }
    vector<int> dp(1<<n);
    repeat (s,1<<n) {
        repeat (i,n) if (not (s & (1<<i))) {
            int acc = dp[s];
            repeat (j,n) if (s & (1<<j)) acc += score[j][i];
            setmax(dp[s | (1<<i)], acc);
        }
    }
    cout << dp[(1<<n)-1] << endl;
    return 0;
}
0