HDU 3406 Baseball of Planet Pandora
Baseball of Planet Pandora
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 275 Accepted Submission(s): 108
One by one, all players of the attacking team goes to the home base and bats the ball thrown by the defending team.
There are four possible results of a bat:
1. “Out”. In this case, the batter misses the ball, so he is disqualified and leaves the game.
2.“Bingle”. In this case, the batter hits the ball, but the ball doesn’t fly out of the field. Then the batter can advance to the first base, and other players of the attacking team who are already on a base can advance to next base (The next base of the third base is the home base). If a player returns to the home base, he scores one point for his team.
3.“Allrun”. In this case, the batter hits the ball out of the field and then all the players on the bases (including the batter) can run to the home base and each scores one point for his team. So in this case, the attacking team can score at least 1 point, and at most 4 points.
4.“Sacrifice”. In this case, the batter chooses not to bat and leaves the field. According to the rule, in this case, the players still on the bases can advance to next base. So the player advancing to the home base this way scores one point. But if there have already been two batters who get an “Out” or a “Sacrifice” before, “Sacrifice” will end the game immediately and the attacking team can’t score any point in this “Sacrifice”.
According to the rule, a player must leave the field immediately after he scores one point for his team. The game ends after every player of the attacking team has batted once(A “Sacrifice” is also regarded as a bat), or after there has been 3 batters who get an “Out” or an “Sacrifice”.
Avatar is the coach of an attacking team. He knows that the same player performs differently when the player takes different turns. For example, if you let Jack to be the first batter, he will definitely get an “Out”, but if you let him play in the third turn, he will get an “Allrun”. Avatar knows his men very well. He asked you to find out the best “batting order” for his team. If the team bats in that order, their score will be maximized.
For each test case:
The first line contains an integer n(1<=n <=15), meaning the number of players in Avatar’s team. All players are numbered for 1 to n.
Then a n×n matrix A follows. Aij describes what result the player i will get if he is the jth batter.( i and j start from 1 )
Following is the meaning of the value of Aij:
0 means the result is “Out”
1 means the result is “Sacrifice”
2 means the result is “Bingle”
3 means the result is “Allrun”
#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; }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。