結果
問題 | No.1284 Flip Game |
ユーザー |
|
提出日時 | 2020-11-07 00:33:48 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,003 bytes |
コンパイル時間 | 1,561 ms |
コンパイル使用メモリ | 175,604 KB |
実行使用メモリ | 22,016 KB |
最終ジャッジ日時 | 2024-07-22 13:56:13 |
合計ジャッジ時間 | 2,903 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 WA * 3 |
ソースコード
#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); int N; cin >> N; vector<vector<int>> c(N, vector<int>(N)); rep(i,N)rep(j,N) cin >> c[i][j]; vector<vector<vector<int>>> dp(1<<N, vector<vector<int>>(1<<N, vector<int>(N, 1e9))); 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] == (int)1e9) continue; rep(l,N){ if(!(j >> l & 1) && i >> k & 1){ int j2 = j | (1 << l); chmin(dp[i][j2][l], dp[i][j][k] + c[k][l]); }else if(!(j >> l & 1)){ int i2 = i | (1 << k); int j2 = (j | (1 << l)) ^ (1 << k); chmin(dp[i2][j2][l], dp[i][j][k] + c[k][l]); } } } int ans = 1e9; rep(i,1<<N)rep(j,N) chmin(ans, dp[i][(1<<N) - 1][j]); cout << ans << '\n'; }