結果

問題 No.357 品物の並び替え (Middle)
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-05-31 00:58:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 886 bytes
コンパイル時間 1,915 ms
コンパイル使用メモリ 150,416 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-08 23:39:14
合計ジャッジ時間 2,922 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.05.31 00:58:15
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int n, m;
    cin >> n >> m;
    vector< int > dp(1 << n, 0);
    vector< vector< pair< int, int > > > v(n);
    for (int i = 0; i < m; i++) {
        int a, b, s;
        cin >> a >> b >> s;
        v[b].push_back({a, s});
    }
    for (int i = 1; i < 1 << n; i++) {
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                int score = 0;
                for (int k = 0; k < v[j].size(); k++) {
                    if (i & (1 << v[j][k].first)) {
                        score += v[j][k].second;
                    }
                }
                dp[i] = max(dp[i], dp[i ^ (1 << j)] + score);
            }
        }
    }
    cout << dp[(1 << n) - 1] << endl;
    return 0;
}
0