結果
| 問題 | No.1284 Flip Game | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-11-07 00:35:46 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 50 ms / 2,000 ms | 
| コード長 | 997 bytes | 
| コンパイル時間 | 1,898 ms | 
| コンパイル使用メモリ | 175,516 KB | 
| 実行使用メモリ | 30,208 KB | 
| 最終ジャッジ日時 | 2024-07-22 13:56:41 | 
| 合計ジャッジ時間 | 3,040 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 28 | 
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
#define chmin(x,y) x = min(x,y)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll N; cin >> N;
    vector<vector<ll>> c(N, vector<ll>(N));
    rep(i,N)rep(j,N) cin >> c[i][j];
    vector<vector<vector<ll>>> dp(1<<N, vector<vector<ll>>(1<<N, vector<ll>(N, 1e18)));
    rep(i,N) dp[0][1<<i][i] = 0;
    rep(i,1<<N)rep(j,(1<<N)-1)rep(k,N){
        if(dp[i][j][k] == (ll)1e18) continue;
        rep(l,N){
            if(!(j >> l & 1) && i >> k & 1){
                ll j2 = j | (1 << l);
                chmin(dp[i][j2][l], dp[i][j][k] + c[k][l]);
            }else if(!(j >> l & 1)){
                ll i2 = i | (1 << k);
                ll j2 = (j | (1 << l)) ^ (1 << k);
                chmin(dp[i2][j2][l], dp[i][j][k] + c[k][l]);
            }
        }
    }
    ll ans = 1e18;
    rep(i,1<<N)rep(j,N) chmin(ans, dp[i][(1<<N) - 1][j]);
    cout << ans << '\n';
}
            
            
            
        