結果

問題 No.357 品物の並び替え (Middle)
ユーザー veqccveqcc
提出日時 2019-02-16 15:28:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 860 bytes
コンパイル時間 743 ms
コンパイル使用メモリ 92,196 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 06:19:36
合計ジャッジ時間 1,777 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int n, m, score[14][14], dp[1 << 14];

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int i1, i2;
        cin >> i1 >> i2 >> score[i1][i2];
    }

    for (int i = 0; i < (1 << n); i++) {
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) continue;

            int tmp = 0;
            for (int k = 0; k < n; k++) {
                if (i & (1 << k)) {
                    tmp += score[k][j];
                }
            }

            dp[i|(1<<j)] = max(dp[i|(1<<j)], dp[i]+tmp);
        }
    }

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