結果
| 問題 |
No.1284 Flip Game
|
| コンテスト | |
| ユーザー |
leaf_1415
|
| 提出日時 | 2020-11-06 23:55:06 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 178 ms / 2,000 ms |
| コード長 | 1,284 bytes |
| コンパイル時間 | 2,379 ms |
| コンパイル使用メモリ | 80,148 KB |
| 実行使用メモリ | 21,760 KB |
| 最終ジャッジ日時 | 2024-07-22 13:51:01 |
| 合計ジャッジ時間 | 3,398 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 |
ソースコード
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(),(x).end()
#define inf 1e18
#define mod 1000000007
using namespace std;
typedef long long llint;
typedef pair<llint, llint> P;
llint n;
llint c[10][10];
llint dp[1<<9][1<<9][9];
int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
rep(i, 0, n-1){
rep(j, 0, n-1){
cin >> c[i][j];
}
}
llint N = 1<<n, ans = inf;
rep(i, 0, N-1){
rep(j, 0, N-1){
rep(k, 0, n-1){
dp[i][j][k] = inf;
}
}
}
rep(i, 0, n-1) dp[0][1<<i][i] = 0;
rep(i, 0, N-1){
rep(j, 0, N-1){
rep(k, 0, n-1){
rep(l, 0, n-1){
if(j & (1<<l)) continue;
llint nj = j | (1<<l);
if((i & (1<<k)) == 0) nj &= ~(1<<k);
else if(nj == N-1) ans = min(ans, dp[i][j][k] + c[k][l]);
chmin(dp[i|(1<<k)][nj][l], dp[i][j][k] + c[k][l]);
}
}
}
}
cout << ans << endl;
return 0;
}
leaf_1415