結果
問題 | No.1284 Flip Game |
ユーザー |
![]() |
提出日時 | 2020-11-11 00:00:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 34 ms / 2,000 ms |
コード長 | 1,733 bytes |
コンパイル時間 | 1,427 ms |
コンパイル使用メモリ | 124,032 KB |
最終ジャッジ日時 | 2025-01-15 22:03:36 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
#include <cstdio>#include <cstring>#include <iostream>#include <string>#include <cmath>#include <bitset>#include <vector>#include <map>#include <set>#include <queue>#include <deque>#include <algorithm>#include <complex>#include <unordered_map>#include <unordered_set>#include <random>#include <cassert>#include <fstream>#include <utility>#include <functional>#include <time.h>#include <stack>#include <array>#define popcount __builtin_popcountusing namespace std;using ll=long long;typedef pair<int, int> P;int main(){int n; cin>>n;ll c[10][10];for(int i=0; i<n; i++){for(int j=0; j<n; j++){cin>>c[i][j];}}const ll INF=1e18;ll dp[9][1<<18];for(int i=0; i<n; i++) fill(dp[i], dp[i]+(1<<(2*n)), INF);for(int i=0; i<n; i++){dp[i][1<<(2*i)]=0;}for(int i=1; i<(1<<(2*n)); i++){for(int j=0; j<n; j++){if(dp[j][i]==INF) continue;int u=((i>>(2*j))&3);for(int k=0; k<n; k++){int t=((i>>(2*k))&3);if(t&1) continue;if(u==1){dp[k][i^(1<<(2*k))^(3<<(2*j))]=min(dp[k][i^(1<<(2*k))^(3<<(2*j))], dp[j][i]+c[j][k]);}else{dp[k][i^(1<<(2*k))]=min(dp[k][i^(1<<(2*k))], dp[j][i]+c[j][k]);}}}}ll ans=INF;for(int i=0; i<n; i++){for(int j=0; j<(1<<(2*n)); j++){bool ok=1;for(int k=0; k<n; k++){if(!(j&(1<<(2*k)))){ok=0;break;}}if(ok) ans=min(ans, dp[i][j]);}}cout<<ans<<endl;return 0;}