标签:des style blog http color os io java strong
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 275 Accepted Submission(s): 108
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <queue> using namespace std; const int N = 17; int n,ans ; int x[N][N]; int dp[1<<N][10][5]; struct node { int a,b,c,w; node(){} node(int aa,int bb,int cc,int ww ){ a=aa , b= bb ,c =cc, w =ww; } }; void init(){ memset( dp , -1 ,sizeof dp ); ans = 0 ; } void bfs() { int a , b , c ,w ; int cnt = 0 ,aa , bb , cc ,ww; queue<node>que ; que.push(node(0,0,0,0)); while( !que.empty() ){ node u = que.front();que.pop(); a = u.a , b = u.b ,c = u.c ,w = u.w ; if( a == (1<<n) -1 || c >= 3 ) { ans = max ( ans , w ); continue; } cnt = 0 ; for(int i = 0; i < n ; ++i ){ if( a&(1<<i) )++cnt; } for(int i = 0; i < n ; ++i ){ if( (a&( 1<<i )) == 0){ int todo = x[i][cnt]; aa= a|(1<<i); if( todo == 0 ){ cc= c + 1; bb = b; ww = w; } else if( todo == 1 ){ if( !b ) bb = 0 , ww = w; else if( b == 1 ) bb = 2,ww=w; else if( b == 2 ) bb = 4,ww=w; else if( b == 3 ) bb = 6,ww=w; else if( b == 4 ) bb = 0,ww=w+1; else if( b == 5 ) bb = 3,ww=w+1; else if( b == 6 ) bb = 4,ww=w+1; else bb = 6,ww=w+1; cc = c+1; } else if( todo == 2 ){ if( b == 0 ) bb = 1 ,ww=w; else if( b == 1 )bb = 3,ww=w; else if( b == 2 )bb = 5,ww=w; else if( b == 3 )bb = 7,ww=w; else if( b == 4 )bb = 1,ww=w+1; else if( b == 5 )bb = 3,ww=w+1; else if( b == 6 )bb = 5,ww=w+1; else bb = 7,ww=w+1; cc = c; } else { if( !b ) ww=w+1; else if( b == 1 || b==2 || b== 4 )ww=w+1; else if( b == 7 )ww=w+4; else ww=w+3; bb = 0; cc = c; } if( dp[aa][bb][cc] < ww ){ dp[aa][bb][cc] = ww; que.push(node(aa,bb,cc,ww)); } } } } } void run() { init(); for(int i =0 ;i < n ;++i ){ for(int j = 0 ; j < n ;++j ){ cin>>x[i][j]; } } bfs(); cout<<ans<<endl; } int main() { #ifdef LOCAL freopen("in.txt","r",stdin); #endif // LOCAL while(cin>>n){ if(!n)break; run(); } return 0; }
HDU 3406 Baseball of Planet Pandora
标签:des style blog http color os io java strong
原文地址:http://www.cnblogs.com/YRETSIM/p/3951362.html