题目链接: http://vjudge.net/problem/viewProblem.action?id=25636

对于>1的堆,必然会被其中一人全部合并。

然后就是二维dp,dp[非1堆的操作数][1堆个数]。

 #include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath> using namespace std;
#define lson o<<1
#define rson o<<1|1
#define max(a,b) (a)>(b)?(a):(b)
#define min(a,b) (a)<(b)?(a):(b)
#define INF 200000000 typedef long long ll;
int dp[][];
int dfs(int one,int tot){
if(dp[one][tot]>-)return dp[one][tot];
if(tot==)return dp[one][tot]=dfs(one+,);
if(one==)return dp[one][tot]=tot&;
if(tot>&&!dfs(one,tot-))return dp[one][tot]=;
if(!dfs(one-,tot))return dp[one][tot]=;
if(tot&&!dfs(one-,tot+))return dp[one][tot]=;
if(one>=)
if((tot&&!dfs(one-,tot+))||(!tot&&!dfs(one-,tot+)))
return dp[one][tot]=; return dp[one][tot]=;
}
int main(){
int t,cs,n;
scanf("%d",&t);
memset(dp,-,sizeof dp);
dp[][]=;
for(cs=;cs<=t;cs++){
scanf("%d",&n);
int x,one=,tot=;
for(int i=;i<n;i++){
scanf("%d",&x);
if(x==)one++;
else
tot+=x+;
}
if(tot)tot--;
printf("Case #%d: ",cs);
if(dfs(one,tot))printf("Alice\n");
else printf("Bob\n");
}
return ;
}

uvalive 5760 Alice and Bob (组合游戏,dp)的更多相关文章

  1. UVaLive 5760 Alice and Bob (博弈 + 记忆化搜索)

    题意:有 n 堆石子,有两种操作,一种是从一堆中拿走一个,另一种是把两堆合并起来,Alice 先拿,谁不能拿了谁输,问谁胜. 析:某些堆石子数量为 1 是特殊,石子数量大于 1 个的都合并起来,再拿, ...

  2. UVALive 5760 Alice and Bob

    题意是黑板上有n个数\(S_i\).每次操作可以把其中一个数减1或者将两个数合并为一个数.一个数变为0时,则不能再对其操作. 思路是发现最大的可操作次数为\( \sum S_i\)+(n - 1).\ ...

  3. 【XSY2190】Alice and Bob VI 树形DP 树剖

    题目描述 Alice和Bob正在一棵树上玩游戏.这棵树有\(n\)个结点,编号由\(1\)到\(n\).他们一共玩\(q\)盘游戏. 在第\(i\)局游戏中,Alice从结点\(a_i\)出发,Bob ...

  4. bzoj4730: Alice和Bob又在玩游戏

    Description Alice和Bob在玩游戏.有n个节点,m条边(0<=m<=n-1),构成若干棵有根树,每棵树的根节点是该连通块内编号最 小的点.Alice和Bob轮流操作,每回合 ...

  5. UVA 1484 - Alice and Bob&#39;s Trip(树形DP)

    题目链接:1484 - Alice and Bob's Trip 题意:BOB和ALICE这对狗男女在一颗树上走,BOB先走,BOB要尽量使得总路径权和大,ALICE要小,可是有个条件,就是路径权值总 ...

  6. hdu 3660 Alice and Bob's Trip(树形DP)

    Alice and Bob's Trip Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  7. [UOJ266]Alice和Bob又在玩游戏

    [UOJ266]Alice和Bob又在玩游戏 Tags:题解 作业部落 评论地址 TAG:博弈 题意 不同于树的删边游戏,删掉一个点删去的是到根的路径 题解 这题只和计算\(SG\)有关,博弈的有关内 ...

  8. UOJ #266 【清华集训2016】 Alice和Bob又在玩游戏

    题目链接:Alice和Bob又在玩游戏 这道题就是一个很显然的公平游戏. 首先\(O(n^2)\)的算法非常好写.暴力枚举每个后继计算\(mex\)即可.注意计算后继的时候可以直接从父亲转移过来,没必 ...

  9. Codeforces 918D MADMAX 图上dp 组合游戏

    题目链接 题意 给定一个 \(DAG\),每个边的权值为一个字母.两人初始各占据一个顶点(可以重合),轮流移动(沿着一条边从一个顶点移动到另一个顶点),要求每次边上的权值 \(\geq\) 上一次的权 ...

随机推荐

  1. 吉哥系列故事――临时工计划(dp)

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Descr ...

  2. COJ 2110 Day7-例3

    Day7-例3 难度级别:C: 运行时间限制:5000ms: 运行空间限制:256000KB: 代码长度限制:2000000B 试题描述 输入 输入的第一行包含整数n和k,其中n(2 ≤ n ≤100 ...

  3. 数学(矩阵乘法):HDU 4565 So Easy!

    So Easy! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  4. 图论(对偶图):COGS 470. [NOI2010]海拔

    470. [NOI2010]海拔 ★★★☆   输入文件:altitude.in   输出文件:altitude.out   简单对比 时间限制:2 s   内存限制:512 MB 海拔 [问题描述] ...

  5. 动态规划 HDU 1176

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

  6. 【二分】NEERC15 L Landscape Improved(2015-2016 ACM-ICPC)(Codeforces GYM 100851)

    题目链接: http://codeforces.com/gym/100851 题目大意: 一个宽度为N的网格图,i上有h[i]高的方块.现在你有W个方块,问怎么放使得最终的最高点最高. 只要一个格子的 ...

  7. cf601A The Two Routes

    A. The Two Routes time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  8. poj1026

    题目大意:暗号 Bod 和 Alice 计划使用一种全新的编码方案,令人惊讶的是这不是一个公开的公匙密码,但是他们的编码基于密匙,在Philadelphia on February 16th他们的会议 ...

  9. iOS状态栏颜色

    下面截图给出修改 iOS 状态栏颜色的 4 种方式 Target.png Info.plist.png Storyboard.png code.png 其中第四张图中的代码,直接写在你的任何一个 Vi ...

  10. Let it Bead

    http://poj.org/problem?id=2409 // File Name: poj2409.cpp // Author: bo_jwolf // Created Time: 2013年1 ...