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 Description
The baseball game of planet Pandora is similar to the game of the Earth. In the game field, there are four bases which are named “home base”, “first base”, “second base” and “third base”. At the beginning, nobody is on the bases. There are two teams, one is 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 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.

 
Input
There are multiple test cases, ended by 0.

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”

 
Output
For each test case, print one line containing the highest score Avatar’s team can get in the game.
 
Sample Input
5
0 2 0 1 2
1 0 2 0 2
0 2 1 2 0
0 2 2 1 2
2 1 0 2 0
0
 
Sample Output
2
 
Source
 
Recommend
wxl   |   We have carefully selected several similar problems for you:  3411 3407 3408 3410 3405 
 
这题是组队赛的一题算是中等题目吧 。 
事实上是比较水的状态压缩。
设一个dp[i][j][k]  ..  i用2进制表示(1<=n<=15)个人batter完还是没batter , j表示垒 ,k表示out和sacrifice的次数 
然后按给出的要求递推一下就好了 。
还要注意一点。要限制一下状态入队。而不是出队的时候把状态continue 掉。  这样就可以省掉一些空间 , 不会MLE
 
 
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue> using namespace std;
const int N = ;
int n,ans ;
int x[N][N];
int dp[<<N][][]; 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 , - ,sizeof dp );
ans = ;
} void bfs()
{
int a , b , c ,w ;
int cnt = ,aa , bb , cc ,ww;
queue<node>que ;
que.push(node(,,,)); while( !que.empty() ){
node u = que.front();que.pop();
a = u.a , b = u.b ,c = u.c ,w = u.w ;
if( a == (<<n) - || c >= ) {
ans = max ( ans , w );
continue;
} cnt = ;
for(int i = ; i < n ; ++i ){
if( a&(<<i) )++cnt;
} for(int i = ; i < n ; ++i ){
if( (a&( <<i )) == ){
int todo = x[i][cnt];
aa= a|(<<i);
if( todo == ){
cc= c + ;
bb = b;
ww = w;
}
else if( todo == ){
if( !b ) bb = , ww = w;
else if( b == ) bb = ,ww=w;
else if( b == ) bb = ,ww=w;
else if( b == ) bb = ,ww=w;
else if( b == ) bb = ,ww=w+;
else if( b == ) bb = ,ww=w+;
else if( b == ) bb = ,ww=w+;
else bb = ,ww=w+;
cc = c+;
}
else if( todo == ){
if( b == ) bb = ,ww=w;
else if( b == )bb = ,ww=w;
else if( b == )bb = ,ww=w;
else if( b == )bb = ,ww=w;
else if( b == )bb = ,ww=w+;
else if( b == )bb = ,ww=w+;
else if( b == )bb = ,ww=w+;
else bb = ,ww=w+;
cc = c;
}
else {
if( !b ) ww=w+;
else if( b == || b== || b== )ww=w+;
else if( b == )ww=w+;
else ww=w+;
bb = ;
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 = ;i < n ;++i ){
for(int j = ; 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 ;
}

HDU 3406 Baseball of Planet Pandora的更多相关文章

  1. HDU 3695-Computer Virus on Planet Pandora(ac自动机)

    题意: 给一个母串和多个模式串,求模式串在母串后翻转后的母串出现次数的的总和. 分析: 模板题 /*#include <cstdio> #include <cstring> # ...

  2. hdu 3695:Computer Virus on Planet Pandora(AC自动机,入门题)

    Computer Virus on Planet Pandora Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 256000/1280 ...

  3. HDU 3695 Computer Virus on Planet Pandora(AC自动机模版题)

    Computer Virus on Planet Pandora Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 256000/1280 ...

  4. HDU 3695 / POJ 3987 Computer Virus on Planet Pandora(AC自动机)(2010 Asia Fuzhou Regional Contest)

    Description Aliens on planet Pandora also write computer programs like us. Their programs only consi ...

  5. hdu 3695 Computer Virus on Planet Pandora(AC自己主动机)

    题目连接:hdu 3695 Computer Virus on Planet Pandora 题目大意:给定一些病毒串,要求推断说给定串中包括几个病毒串,包括反转. 解题思路:将给定的字符串展开,然后 ...

  6. hdu 3695 10 福州 现场 F - Computer Virus on Planet Pandora 暴力 ac自动机 难度:1

    F - Computer Virus on Planet Pandora Time Limit:2000MS     Memory Limit:128000KB     64bit IO Format ...

  7. hdu ----3695 Computer Virus on Planet Pandora (ac自动机)

    Computer Virus on Planet Pandora Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 256000/1280 ...

  8. HDU 3695 / POJ 3987 Computer Virus on Planet Pandora

      Computer Virus on Planet Pandora Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1353 ...

  9. HDU-3695 Computer Virus on Planet Pandora

    HDU-3695 Computer Virus on Planet Pandora 题意:电脑中病毒了, 现在n钟病毒指令, 然后有一个电脑指令, 看一下这个电脑指令中了几个病毒, 如果电脑种了某一个 ...

随机推荐

  1. turtle库使用

    turtle库的使用 绘图窗体布局 turtle.setup(width,height,startx,straty) 用来控制窗体的大小与位置,其中后width与height用来控制窗体的大小,sta ...

  2. JetbrainsCrack-4.2-release-enc.jar 激活补丁包

    http://wangshuo.jb51.net:81/201904/tools/JetbrainsCrack_jb51.rar ps:这里提供jetbrainscrack-2.10.jar.jetb ...

  3. thinkphp在 nginx 的conf文件配置

    server { listen 80; server_name www.osd-aisa.com; #charset koi8-r; #access_log logs/host.access.log ...

  4. how to pass variable from shell script to sqlplus

    script sqlplus ${ORA_USR}/${ORA_PASS}@${ORA_DB} @${PARM}/TEST $new_usr $model_usr $new_pwd parm of s ...

  5. nuxtJs - axios 的 IE 兼容性的问题

    因为考虑SEO, 所以采用nuxt.js进行服务端渲染, 用熟了vue, nuxt无缝对接简直不要太爽 烦人的需求又来了, 要兼容IE ~~ 兼容处理 无非就是babel 将高级语法转成弱智IE看得懂 ...

  6. svnkit 异常:Exception in thread "main" org.tmatesoft.svn.core.SVNException: svn: E200030: SQLite error

    https://stackoverflow.com/questions/16063105/org-tmatesoft-sqljet-core-sqljetexception-busy-error-co ...

  7. Java中的String、StringBuffer、StringBuilder区别以及Java之StringUtils的用法

    1.String.StringBuffer.StringBuilder的区别 String是Java中基础类型,是immutable类(不可变)的典型实现,利用string进行拼接是会产生过多无用对象 ...

  8. 通过注释查找mysql的表名

    通过注释查找mysql的表名 select * from INFORMATION_SCHEMA.columns where COLUMN_NAME Like '%placement%';

  9. centos 6.5 配置网络

    编辑 vi /etc/sysconfig/network-scripts/ifcfg-eth0 修改内容 DEVICE="eth0" BOOTPROTO="static& ...

  10. 命令查看当前运行APP的包名和Activity

    先用usb链接手机 启动要查看的程序,命令查看当前运行的包名和Activity更清晰. 使用adb shell dumpsys window | findstr mCurrentFocus  命令查看 ...