結果

問題 No.943 取り調べ
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-06-18 19:34:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 75 ms / 1,206 ms
コード長 1,088 bytes
コンパイル時間 3,528 ms
コンパイル使用メモリ 148,384 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 12:17:51
合計ジャッジ時間 4,812 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.06.18 19:34:15
**/

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

int main() {
    int n;
    cin >> n;
    vector< vector< int > > x(n, vector< int >(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> x[i][j];
        }
    }
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    constexpr int INF = 1e9 + 6;
    vector< int > dp(1 << n, INF);
    dp[0] = 0;
    for (int i = 0; i < 1 << n; i++) {
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                for (int k = 0; k < n; k++) {
                    if (x[j][k] == 1 && !(i & (1 << k))) {
                        dp[i] = min(dp[i],dp[i ^ (1 << j)] + a[j]);
                        break;
                    }
                    else if(k == n-1) {
                        dp[i] = min(dp[i],dp[i ^ (1 << j)]);
                    }
                }
            }
        }
    }
    cout << dp[(1 << n) - 1] << endl;
    return 0;
}
0