HDU 3406 Baseball of Planet Pandora

Source: Internet
Author: User

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


Problem DescriptionThe Baseball Game of Planet Pandora is similar to the game of the Earth. In the game field, there is four bases which is named "Home base", "first base", "second base" and "third base". At the beginning, nobody are on the bases. There is the teams, the one was the attacking team, and the other is the defending team.

One by one, all players of the attacking team goes to the home base and bats the ball thrown by the defending team.

There is four possible results of a bat:
1. "Out". The the batter misses the ball, so he is disqualified and leaves the game.

2. "Bingle". The batter hits the ball and the ball doesn ' t fly out of the field. Then the batter can advance to the first base, and all players of the attacking team who is already on a base can Advan Ce 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". The the batter hits the ball out of the field and then all the players on the bases (including the batter) can R UN to the home base and each scores one point for his team. The attacking team can score at least 1, and at most 4 points.

4. "Sacrifice". The batter chooses not to bat and leaves the field. According to the rule, the players still on the bases can advance to next base. So the player advancing to the home base this-to-scores one point. But if there has already been and batters who get an "out" or a "sacrifice" before, "sacrifice" would end the game Immedia Tely and the attacking team can ' t score any of 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 have batted once (a "sacrifice" is also regarded as A bat), or after There has been 3 batters the WHO get a "out" or "sacrifice".

Avatar is the coach of an attacking team. He knows the same player performs differently when the player takes different turns. For example, if-let Jack-to-be the first batter, he'll definitely get an ' out ', but if-you-let-him play in the third Turn, he'll get an "allrun". Avatar knows his men, very well. He asked the best "batting order" for his team. If the team bats in that order, their score'll be maximized.

Inputthere is multiple test cases, ended by 0.

For each test case:
The first line contains a integer n (1<=n <=15), meaning the number of players in Avatar ' s team. All players is numbered for 1 to N.

Then a nxn matrix a follows. Aij describes what result the player I'll 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"

Outputfor each test case, print one line containing the highest score Avatar ' s team can get in the game.

Sample Input50 2 0 1 21 0 2 0 20 2 1 2 00 2 2 1 22 1 0 2 00

Sample Output2

SOURCE2010 National Programming Invitational Contest Host by Zstu

RECOMMENDWXL | We have carefully selected several similar problems for you:3411 3407 3408 3410 3405 The question is a medium-sized topic for a team game. In fact, it is compared to the state compression of water.  Set a dp[i][j][k]. I use 2 notation (1<=n<=15) personal batter or not batter, j for base, K for out and sacrifice the number of times and then according to the requirements given to push a bit better. One more thing to note. To limit the status of the queue.  Instead of continue the state when you're out of the team. So that you can save some space, not the MLE
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<queue>using namespacestd;Const intN = -;intN,ans;intX[n][n];intdp[1<<n][Ten][5];structnode{inta,b,c,w; Node () {} node (intCanintBbintCcintww) {a=AA, b= BB, c =cc, w =ww; }};voidinit () {memset (DP,-1,sizeofDP); Ans=0 ;}voidBFs () {intA, B, C, W; intCNT =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(inti =0; I < n; ++i) {            if(a& (1<<i)) + +CNT; }         for(inti =0; I < n; ++i) {            if((a& (1<<i)) = =0){                intTodo =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; ElseBB =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; ElseBB =7, ww=w+1; CC=C; }                Else {                    if(!b) ww=w+1; Else if(b = =1|| d={2|| d={4) ww=w+1; Else if(b = =7) ww=w+4; Elseww=w+3; BB=0; CC=C; }                if(DP[AA][BB][CC] <ww) {DP[AA][BB][CC]=ww;                Que.push (Node (AA,BB,CC,WW)); }            }        }    }}voidrun () {init ();  for(inti =0; i < n; + +i) {         for(intj =0; J < N; + +j) {cin>>X[i][j];    }} BFS (); cout<<ans<<Endl;}intMain () {#ifdef LOCAL freopen ("In.txt","R", stdin); #endif //LOCAL     while(cin>>N) {        if(!n) Break;    Run (); }    return 0;}

HDU 3406 Baseball of Planet Pandora

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.