Alice and Bob

Time Limit: 20 Sec  Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=4111

Description

Alice and Bob are very smart guys and they like to play all kinds of games in their spare time. The most amazing thing is that they always find the best strategy, and that's why they feel bored again and again. They just invented a new game, as they usually did.
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

3 3 1 1 2 2 3 4 3 2 3 5

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 记忆化搜索 博弈论的更多相关文章

  1. hdu 4111 Alice and Bob(中档博弈题)

    copy VS study 1.每堆部是1的时候,是3的倍数时输否则赢: 2.只有一堆2其他全是1的时候,1的堆数是3的倍数时输否则赢: 3.其他情况下,计算出总和+堆数-1,若为偶数,且1的堆数是偶 ...

  2. HDU 1176 免费馅饼(记忆化搜索)

    免费馅饼 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  3. HDU 1428 漫步校园(记忆化搜索,BFS, DFS)

    漫步校园 http://acm.hdu.edu.cn/showproblem.php?pid=1428 Problem Description LL最近沉迷于AC不能自拔,每天寝室.机房两点一线.由于 ...

  4. hdu 1142(迪杰斯特拉+记忆化搜索)

    A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  5. hdu 1176免费馅饼(记忆化搜索)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1176 题意不解释了 简单的记忆化搜索可以拿来练练手,注意要从pos = 5 开始搜索 #include ...

  6. HDU 1078 FatMouse and Cheese 记忆化搜索DP

    直接爆搜肯定超时,除非你加了某种凡人不能想出来的剪枝...555 因为老鼠的路径上的点满足是递增的,所以满足一定的拓补关系,可以利用动态规划求解 但是复杂的拓补关系无法简单的用循环实现,所以直接采取记 ...

  7. HDU 2476 String painter(记忆化搜索, DP)

    题目大意: 给你两个串,有一个操作! 操作时可以把某个区间(L,R) 之间的所有字符变成同一个字符.现在给你两个串A,B要求最少的步骤把A串变成B串. 题目分析: 区间DP, 假如我们直接想把A变成B ...

  8. hdu 5389 Zero Escape(记忆化搜索)

    Problem Description Zero Escape, is a visual novel adventure video game directed by Kotaro Uchikoshi ...

  9. HDU - 1078 FatMouse and Cheese (记忆化搜索)

    FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension ...

随机推荐

  1. oracle查看表中数据的大小

    通过从视图 user_segments的字段 bytes中找到 select SUM(bytes)/1024/1024 from user_segments where segment_name='E ...

  2. 77.PS接收来自PL的按键中断

    本篇文章主要介绍外设(PL)产生的中断请求,在PS端进行处理. 在PL端通过按键产生中断,PS接受到之后点亮相应的LED. 本文所使用的开发板是zedboardPC 开发环境版本:Vivado 201 ...

  3. C++之 extern C的作用详解

    extern "C"的主要作用就是为了能够正确实现C++代码调用其他C语言代码.加上extern "C"后,会指示编译器这部分代码按C语言的进行编译,而不是C+ ...

  4. JavaScript 跳转 页面

    * window.location.href , self.location, window.location 出现问题不能跳转 Chome 不能本页跳转, IE 有时可以

  5. 响应式设计:根据不同设备引不同css样式

    <link rel="stylesheet" media="screen and (max-width:600px)" href="small. ...

  6. Python/Anaconda多版本共存的解决方案

    博客中的文章均为 meelo 原创,请务必以链接形式注明 本文地址 虽然Python2大势已去,众多项目都已经支持Python3,但总有一些教程和项目只支持Python2.通常情况是计算机里既装着Py ...

  7. 一个配置文件收集多个日志-if根据type类型判断

    1.同时收集/var/log/messages日志和secure日志 #vim /etc/logstash/conf.d/system.conf input { file { path => & ...

  8. 接口自动化多层嵌套的json数据处理

    最近在做接口自动化测试,响应的内容大多数是多层嵌套的json数据,在对响应数据进行校验的时候,可以通过(key1.key2.key3)形式获取嵌套字典值的方法获取响应值,再和预期值比较 def get ...

  9. Linux与其它类Unix内核的比较

    单块结构的内核:由几个逻辑上独立的成分构成,单块结构,大多数据商用Unix变体也是单块结构: 编译并静态连接的传统Unix内核:Linux能自动按需动态地装载和卸载部分内核代码(模块),而传统Unix ...

  10. EL和JSTL的关系

    JSTL与EL的关系:EL的功能是有限的,去集合只能取特定的某一个元素,如果遍历或循环就不行了,或者添加一些条件分支判断也不行,或做一些格式化,比如日期的格式化,数字的格式化,也不行,所以要做这些功能 ...