結果
問題 | No.1284 Flip Game |
ユーザー |
![]() |
提出日時 | 2020-09-03 22:32:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 61 ms / 2,000 ms |
コード長 | 1,042 bytes |
コンパイル時間 | 696 ms |
コンパイル使用メモリ | 75,756 KB |
実行使用メモリ | 7,680 KB |
最終ジャッジ日時 | 2024-11-26 10:38:33 |
合計ジャッジ時間 | 2,033 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
#include <iostream>#include <vector>#include <algorithm>#include <cmath>#include <cassert>#define rep(i,n) for(int i=0; i<(int)(n); i++)using namespace std;using LL = long long;const int Max_N = 10;const int Max_C = 1e8;const int Max_S = 1e5;const int INF = 2e9+5;int N, M, fin;int c[Max_N][Max_N];int dp[Max_S][Max_N];int rec(int s, int v){if(dp[s][v]!=INF) return dp[s][v];int res=INF;rep(u,N){if(u==v and s!=fin) continue;int div=pow(M,u);if(s/div%M==0) continue;int ns=s-pow(M,v);res=min(res,rec(ns,u)+c[u][v]);}return dp[s][v]=res;}int main(){cin >> N;assert(2<=N and N<=Max_N);M=3;fin=pow(M,N)-1;rep(i,N){rep(j,N){cin >> c[i][j];if(i==j) assert(c[i][j]==0);else assert(1<=c[i][j] and c[i][j]<=Max_C);}}rep(i,Max_S){rep(j,Max_N) dp[i][j]=INF;}rep(i,N){int st=pow(3,i);dp[st][i]=0;}rep(i,N) rec(fin,i);int ans=INF;rep(i,N) ans=min(ans,dp[fin][i]);cout << ans << endl;return 0;}