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钟病毒指令, 然后有一个电脑指令, 看一下这个电脑指令中了几个病毒, 如果电脑种了某一个 ...
随机推荐
- Git配置全局账号密码避免每次拉取、提交输入账号密码
前言 在大家使用github的过程中,一定会碰到这样一种情况,就是每次要push 和pull时总是要输入github的账号和密码,这样不仅浪费了大量的时间且降低了工作效率.在此背景下,本文在网上找了两 ...
- R语言数据类型与数据结构
一.数据类型 5种 1.character 字符 2.numeric 数值 3.integer 整数 一般数字的存储会默认为数值类型,如果要强调是整数,需要在变量值后面加上 L. x <- 5L ...
- 记一次sql索引颠覆认知
首先先建立数据库和插入数据 我们要查询的命令如下,前提是以mysql数据库为准 , 结果和我想的不太一样,先准备好环境和所需的数据库和表 准备阶段 CREATE TABLE `test` ( `id` ...
- tensorflow教程:tf.contrib.rnn.DropoutWrapper
tf.contrib.rnn.DropoutWrapper Defined in tensorflow/python/ops/rnn_cell_impl.py. def __init__(self, ...
- java两个引用指向同一个对象
- spring cloud学习笔记二 ribbon负载均衡
Ribbon是Netflix发布的负载均衡器,它有助于控制HTTP和TCP的客户端的行为.为Ribbon配置服务提供者地址后,Ribbon就可基于某种负载均衡算法,自动地帮助服务消费者去请求.Ribb ...
- postgresql绿色版安装及Navicat创建数据库,导入导出sql
转载:https://www.cnblogs.com/winkey4986/p/5360551.html 1.设置安装路径为:D:\soft\pgsql,数据存储路径为:D:\soft\pgsql\d ...
- $NOIP2018$ 暴踩全场计划实施方案
\(NOIP2018\) 暴踩全场计划实施方案 改完题辣!该更博辣!(这么激动干嘛反正又没人看) 我要取一个霸气的名字.于是就这样了.原本打算是暴踩yyb计划实施方案的(来啊互相伤害啊) 信心流选手就 ...
- 人生苦短_我用Python_Try_Exception异常捕捉_007
# coding=utf-8 ''' request+try__异常处理 ''' import requests class HttpRequests: def __init__(self, url, ...
- find命令查找目录
find <path> -type d -name "dir_name" -type d是查找目录的参数,如果是查找其他的: -type b: Block specia ...