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. ELK + Filebeat日志分析系统安装

    之前搭建过elk,用于分析日志,无奈服务器资源不足,开了多个Logstash之后发现占用内存过高,于是现在改为Filebeat做日志收集,记录一下搭建过程和遇到问题的解决方案. 第一步 , 安装jdk ...

  2. JavaScript——面向对象编程

    什么是面向对象? 面向对象编程(Object Oriented Programming,OOP编程)是一种计算机编程架构,它将真实世界各种复杂的关系,抽象为一个个对象,然后由对象之间的分工与合作,完成 ...

  3. 98-基于FPGA Spartan6 的双路光纤PCIe采集卡(2路光纤卡)

    基于FPGA Spartan6 的双路光纤PCIe采集卡(2路光纤卡) 1.板卡概述  板卡采用xilinx Spartan6系列芯片,支持 PCI Express Base Specificatio ...

  4. Strings=newString(“xyz”);创建了几个 StringObject?

    两个对象,一个是"xyx",一个是指向"xyx"的引用对象 s

  5. Autodesk Maya 2019 for Mac(三维动画软件)最新功能介绍

    Autodesk Maya是美国Autodesk公司出品的世界顶级的三维动画软件,应用对象是专业的影视广告,角色动画,电影特技等.Maya功能完善,工作灵活,易学易用,制作效率极高,渲染真实感极强,是 ...

  6. Java Web学习总结(7)JSP(一)

    一,JSP基础语法 1,JSP模板元素 JSP页面中的HTML内容称之为JSP模版元素. JSP模版元素定义了网页的基本骨架,即定义了页面的结构和外观. 2,JSP脚本片段 JSP脚本片断(scrip ...

  7. sql查看数据库环境及一些参数

    sql查看数据库环境及一些参数 select parent_obj from sysobjects where name='FK_Student_banjiID' --根据外键名得到外表id sele ...

  8. 2017 ACM-ICPC乌鲁木齐网络赛 B. Out-out-control cars(计算几何 直线相交)

    题目描述 Two out-of-control cars crashed within about a half-hour Wednesday afternoon on Deer Park Avenu ...

  9. 【SPOJ8222】Substrings (后缀自动机)

    题意: 给一个字符串S,令F(x)表示S的所有长度为x的子串中,出现次数的最大值. 求F(1)..F(Length(S)) Length(S) <= 250000 思路:板子中st[x]定义为r ...

  10. hashmap:cr:csdn

    HashMap相关问题 1.你用过HashMap吗?什么是HashMap?你为什么用到它? 用过,HashMap是基于哈希表的Map接口的非同步实现,它允许null键和null值,且HashMap依托 ...