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钟病毒指令, 然后有一个电脑指令, 看一下这个电脑指令中了几个病毒, 如果电脑种了某一个 ...
随机推荐
- turtle库使用
turtle库的使用 绘图窗体布局 turtle.setup(width,height,startx,straty) 用来控制窗体的大小与位置,其中后width与height用来控制窗体的大小,sta ...
- JetbrainsCrack-4.2-release-enc.jar 激活补丁包
http://wangshuo.jb51.net:81/201904/tools/JetbrainsCrack_jb51.rar ps:这里提供jetbrainscrack-2.10.jar.jetb ...
- thinkphp在 nginx 的conf文件配置
server { listen 80; server_name www.osd-aisa.com; #charset koi8-r; #access_log logs/host.access.log ...
- 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 ...
- nuxtJs - axios 的 IE 兼容性的问题
因为考虑SEO, 所以采用nuxt.js进行服务端渲染, 用熟了vue, nuxt无缝对接简直不要太爽 烦人的需求又来了, 要兼容IE ~~ 兼容处理 无非就是babel 将高级语法转成弱智IE看得懂 ...
- 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 ...
- Java中的String、StringBuffer、StringBuilder区别以及Java之StringUtils的用法
1.String.StringBuffer.StringBuilder的区别 String是Java中基础类型,是immutable类(不可变)的典型实现,利用string进行拼接是会产生过多无用对象 ...
- 通过注释查找mysql的表名
通过注释查找mysql的表名 select * from INFORMATION_SCHEMA.columns where COLUMN_NAME Like '%placement%';
- centos 6.5 配置网络
编辑 vi /etc/sysconfig/network-scripts/ifcfg-eth0 修改内容 DEVICE="eth0" BOOTPROTO="static& ...
- 命令查看当前运行APP的包名和Activity
先用usb链接手机 启动要查看的程序,命令查看当前运行的包名和Activity更清晰. 使用adb shell dumpsys window | findstr mCurrentFocus 命令查看 ...