hdu 4111 Alice and Bob 记忆化搜索 博弈论
Alice and Bob
Time Limit: 20 Sec Memory Limit: 256 MB
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=4111
Description
The rule of the
new game is quite simple. At the beginning of the game, they write down N
random positive integers, then they take turns (Alice first) to either:
1. Decrease a number by one.
2. Erase any two numbers and write down their sum.
Whenever
a number is decreased to 0, it will be erased automatically. The game
ends when all numbers are finally erased, and the one who cannot play in
his(her) turn loses the game.
Here's the problem: Who will win the
game if both use the best strategy? Find it out quickly, before they get
bored of the game again!
Input
The first line contains an integer T(1 <= T <= 4000), indicating the number of test cases.
Each test case contains several lines.
The first line contains an integer N(1 <= N <= 50).
The next line contains N positive integers A1 ....AN(1 <= Ai <= 1000), represents the numbers they write down at the beginning of the game.
Output
For each test case in the input, print one line: "Case #X: Y", where X is the test case number (starting with 1) and Y is either "Alice" or "Bob".
Sample Input
Sample Output
Case #1: Alice
Case #2: Bob
Case #3: Bob
HINT
题意
给你n堆石头,你有两个选择,1.减少一堆石头数量1,2.合并两堆石头
如果遇到不能操作的情况就算输
题解:
这道题当成dp来做,dp[i][j]表示现在有i堆只有1个,j表示现在我能够操作次数
操作次数等于 sigma(a[i])-n+1,其中a[i]>1,n为满足条件的a[i]的个数
------------------------
那么转移方程就出来了,1个的,要么消去,要么和1个的合并,要么和多个的合并
然后就可以记忆化搜索搞了
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 50051
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int dp[][maxn];
int a[maxn]; int dfs(int a,int b)//a 表示还有多少组为1 b表示还剩下多少次操作次数
{
if(dp[a][b]!=-)
return dp[a][b];
dp[a][b]=;//其他情况都是不可操作的
if(b==)
return dp[a][b]=dfs(a+,);//只剩一个单独的一,加入其它1中
if(a>=&&!dfs(a-,b))//直接去掉一个1
dp[a][b]=;
if(a>=&&b&&!dfs(a-,b+))//将一个1合到其它数中
dp[a][b]=;
if(a>=&&((b&&!dfs(a-,b+))||(b==&&!dfs(a-,))))//将2个1并起来
dp[a][b]=;
if(b>=&&!dfs(a,b-))//减小一
dp[a][b]=; return dp[a][b];
} int main()
{
//freopen("test.txt","r",stdin);
memset(dp,-,sizeof(dp));
int t=read();
for(int cas=;cas<=t;cas++)
{
int flag=;
int sum=;
int n=read();
for(int i=;i<n;i++)
{
a[i]=read();
if(a[i]==)
flag++;
else
sum+=a[i]+;
}
sum--;
dfs(flag,sum);
if(dp[flag][sum])
printf("Case #%d: Alice\n",cas);
else
printf("Case #%d: Bob\n",cas);
}
}
hdu 4111 Alice and Bob 记忆化搜索 博弈论的更多相关文章
- hdu 4111 Alice and Bob(中档博弈题)
copy VS study 1.每堆部是1的时候,是3的倍数时输否则赢: 2.只有一堆2其他全是1的时候,1的堆数是3的倍数时输否则赢: 3.其他情况下,计算出总和+堆数-1,若为偶数,且1的堆数是偶 ...
- HDU 1176 免费馅饼(记忆化搜索)
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- HDU 1428 漫步校园(记忆化搜索,BFS, DFS)
漫步校园 http://acm.hdu.edu.cn/showproblem.php?pid=1428 Problem Description LL最近沉迷于AC不能自拔,每天寝室.机房两点一线.由于 ...
- hdu 1142(迪杰斯特拉+记忆化搜索)
A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- hdu 1176免费馅饼(记忆化搜索)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1176 题意不解释了 简单的记忆化搜索可以拿来练练手,注意要从pos = 5 开始搜索 #include ...
- HDU 1078 FatMouse and Cheese 记忆化搜索DP
直接爆搜肯定超时,除非你加了某种凡人不能想出来的剪枝...555 因为老鼠的路径上的点满足是递增的,所以满足一定的拓补关系,可以利用动态规划求解 但是复杂的拓补关系无法简单的用循环实现,所以直接采取记 ...
- HDU 2476 String painter(记忆化搜索, DP)
题目大意: 给你两个串,有一个操作! 操作时可以把某个区间(L,R) 之间的所有字符变成同一个字符.现在给你两个串A,B要求最少的步骤把A串变成B串. 题目分析: 区间DP, 假如我们直接想把A变成B ...
- hdu 5389 Zero Escape(记忆化搜索)
Problem Description Zero Escape, is a visual novel adventure video game directed by Kotaro Uchikoshi ...
- HDU - 1078 FatMouse and Cheese (记忆化搜索)
FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension ...
随机推荐
- AngularJs 文件上传(实现Multipart/form-data 文件的上传)
<!-- 上传yml文件 --> <div class="blackBoard" ng-show="vm.showUpop==true"> ...
- PostGIS 操作geometry方法
WKT定义几何对象格式: POINT(0 0) ——点 LINESTRING(0 0,1 1,1 2) ——线 POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1, 2 1, 2 2 ...
- CentOS 7.1使用yum安装MySql5.6.24
http://www.cnblogs.com/yuanfeiblog/p/5276492.html
- deep learning 资源汇总
不定时更新..... 首先是吴老爷子在优酷的视频,可惜外音太大了:http://list.youku.com/albumlist/show?id=21508721&ascending=1&am ...
- HDU 4725 The Shortest Path in Nya Graph(spfa+虚拟点建图)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4725 题目大意:有n层,n个点分布在这些层上,相邻层的点是可以联通的且距离为c,还有额外给出了m个条边 ...
- poj 1041(字典序输出欧拉回路)
John's trip Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8641 Accepted: 2893 Spe ...
- es6 class 中 constructor 方法 和 super
首先,ES6 的 class 属于一种“语法糖”,所以只是写法更加优雅,更加像面对对象的编程,其思想和 ES5 是一致的. <1>constructor function Point(x, ...
- bzoj 1113
思路:对于两张高度一样的海报 i, j, 即 y[ i ] = y[ j ], 如果对于任意i < k < j 有y[ k ] > y[ i ] && y[ k ] ...
- web学习测试环境
ref:https://www.owasp.org/index.php/OWASP_Vulnerable_Web_Applications_Directory_Project/Pages/Offlin ...
- GeneXus手机开发基础配置
最近使用GeneXus15 U3版本做了几个手机端的项目,感觉还不错,开发速度很快,而且想要的功能也都实现了.其中有一些常用的配置和小技巧和大家分享一下. 基础环境要求 如果想开发Android程序, ...