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”
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
#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的更多相关文章
- HDU 3695-Computer Virus on Planet Pandora(ac自动机)
题意: 给一个母串和多个模式串,求模式串在母串后翻转后的母串出现次数的的总和. 分析: 模板题 /*#include <cstdio> #include <cstring> # ...
- hdu 3695:Computer Virus on Planet Pandora(AC自动机,入门题)
Computer Virus on Planet Pandora Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 256000/1280 ...
- HDU 3695 Computer Virus on Planet Pandora(AC自动机模版题)
Computer Virus on Planet Pandora Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 256000/1280 ...
- 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 ...
- hdu 3695 Computer Virus on Planet Pandora(AC自己主动机)
题目连接:hdu 3695 Computer Virus on Planet Pandora 题目大意:给定一些病毒串,要求推断说给定串中包括几个病毒串,包括反转. 解题思路:将给定的字符串展开,然后 ...
- 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 ...
- hdu ----3695 Computer Virus on Planet Pandora (ac自动机)
Computer Virus on Planet Pandora Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 256000/1280 ...
- HDU 3695 / POJ 3987 Computer Virus on Planet Pandora
Computer Virus on Planet Pandora Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1353 ...
- HDU-3695 Computer Virus on Planet Pandora
HDU-3695 Computer Virus on Planet Pandora 题意:电脑中病毒了, 现在n钟病毒指令, 然后有一个电脑指令, 看一下这个电脑指令中了几个病毒, 如果电脑种了某一个 ...
随机推荐
- spring(二):bean的生命周期
bean的生命周期指的是bean的创建——>初始化——>销毁的过程,该过程是由spring容器进行管理的 我们可以自定义bean初始化和销毁的方法:容器在bean进行到当前生命周期时,调用 ...
- Iplimage versus Mat
我们可能经常面临这样的困惑,Iplimage和Mat这两种数据结构,我们应该用哪一种数据结构. Iplimage一开始就存在opencv库之中,他来源于Intel的另外一个函数库Intel Image ...
- jsp页面必填项如何加红星号*
1.加*号 并且设置*号大小 <span style="color:red; font-size: 20px">*</span>
- 解析天启rk3288源码 /kernel/drivers/char/virtd
virtd为编译后产生的中间文件,可使用ELF格式逆向 1.ELF文件内容解析readelf: 可解析ELF文件的所有内容;strings: 查看ELF文件中的字符串;file : 查看ELF文件 ...
- spring的@Value注解使用
https://blog.csdn.net/woheniccc/article/details/79804600 昨天看到了springMVC的controller中的属性使用了@value注解,并且 ...
- Linux学习笔记之磁盘与文件系统的管理
三.Linux磁盘与文件系统的管理 MBR扇区(512B) 磁盘的分区组成 Boot sector 扇区(用来装引导程序) Super block 记录inode与Block的信息 Inod ...
- javaweb各种框架组合案例(四):maven+spring+springMVC+spring data jpa(hibernate)【失败案例】
一.失败案例 1. 控制台报错信息 严重: Exception sending context initialized event to listener instance of class org. ...
- Java1.7与1.8新特性
Java 1.7: switch中可以使用字符串 List<String> list = new ArrayList<>(),即泛型实例化类型自动推断 try块可以不用fina ...
- 新装ubantu 18.04(自用)
1.下载镜像,制作u盘启动,装机,分区(具体的百度) 2.sudo passwd root 给root用户创建密码 3.解压tar.gz文件 sudo tar -zxvf pycharm.t ...
- Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)
Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...