题意:给定 n 堆石头,然后有两种操作,一种是把从任意一堆拿走一个,另一种是把一个石子放到另一堆上。

析:整体看,这个题真是不好做,dp[a][b] 表示有 a 堆1个石子,b个操作,操作是指把其他的不是1的堆全部合并起来并全部拿完所以要的操作,

要注意的是 ,一共有这几种情况。

1.a 为0,说明没有一堆的,全是另一种操作,这一种是看操作个数,如果是奇数,先手胜。

2.a 为 1,说明只有只有一堆 为1的, 这个是先手必胜,因为如果 b是偶数,那么就可以先合并,如果是 b 是奇数,就是直接拿掉。

3.b 为 1,说明最后那个也只剩下一个了,要把 b 放到 a 上。

3.从 a 中拿走一个。

4.从 b 中拿走一个。

5.合并 a 中的一个石子到 b。

6.合并 a 中的两个石子,然后就不再是一个了,就得放到 b 上。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1000 + 5;
const int mod = 10;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} int dp[55][50*maxn]; int dfs(int a, int b){
int &ans = dp[a][b];
if(ans != -1) return ans;
if(0 == a) return ans = b & 1;
if(1 == a) return ans = 1;
if(1 == b) return ans = dfs(a+1, b-1); //take the second to the one
if(!dfs(a-1, b)) return ans = 1; //from the one select one
if(b > 0 && !dfs(a, b-1)) return ans = 1; //from the second select one
if(b > 0 && !dfs(a-1, b+1)) return ans = 1; //unit the one to the second
if(a > 1 && !dfs(a-2, b ? b+3 : b+2)) return ans = 1; //unit the two from the one to the second
return ans = 0;
} int main(){
int T; cin >> T;
memset(dp, -1, sizeof dp);
for(int kase = 1; kase <= T; ++kase){
scanf("%d", &n);
int a = 0, b = 0;
for(int i = 0; i < n; ++i){
int x;
scanf("%d", &x);
if(1 == x) ++a;
else b += x + 1;
}
printf("Case #%d: %s\n", kase, dfs(a, b-1) ? "Alice" : "Bob");
}
return 0;
}

  

HDU 4111 Alice and Bob (博弈+记忆化搜索)的更多相关文章

  1. BZOJ 3895 3895: 取石子 / Luogu SP9934 ALICE - Alice and Bob (博弈 记忆化搜索)

    转自PoPoQQQ大佬博客 题目大意:给定n堆石子,两人轮流操作,每个人可以合并两堆石子或拿走一个石子,不能操作者输,问是否先手必胜 直接想很难搞,我们不妨来考虑一个特殊情况 假设每堆石子的数量都&g ...

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

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

  3. hdu 4111 Alice and Bob 记忆化搜索 博弈论

    Alice and Bob Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

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

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

  5. HDU 4597 Play Game (DP,记忆化搜索,博弈)

    题意:Alice和Bob玩一个游戏,有两个长度为N的正整数数字序列,每次他们两个,只能从其中一个序列,选择两端中的一个拿走.他们都希望可以拿到尽量大的数字之和, 并且他们都足够聪明,每次都选择最优策略 ...

  6. HDU 4960 Another OCD Patient(记忆化搜索)

    HDU 4960 Another OCD Patient pid=4960" target="_blank" style="">题目链接 记忆化 ...

  7. CodeForces 918D MADMAX(博弈+记忆化搜索)

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

  8. 随手练——HDU 1078 FatMouse and Cheese(记忆化搜索)

    http://acm.hdu.edu.cn/showproblem.php?pid=1078 题意: 一张n*n的格子表格,每个格子里有个数,每次能够水平或竖直走k个格子,允许上下左右走,每次走的格子 ...

  9. HDU 1428 漫步校园 (BFS+优先队列+记忆化搜索)

    题目地址:HDU 1428 先用BFS+优先队列求出全部点到机房的最短距离.然后用记忆化搜索去搜. 代码例如以下: #include <iostream> #include <str ...

随机推荐

  1. C++的引用类型【转载】

    c++比起c来除了多了类类型外还多出一种类型:引用.这个东西变量不象变量,指针不象指针,我以前对它不太懂,看程序时碰到引用都稀里糊涂蒙过去.最近把引用好好地揣摩了一番,小有收获,特公之于社区,让初学者 ...

  2. 微信小程序之巧妙的封装

    巧妙的封装 暴露一个访问地址xapp.config.js module.exports = { api_host: `https://a.squmo.com/yizu` } 继续引入,加暴露api.c ...

  3. oracle里的查询转换

    oracle里的查询转换的作用 Oracle里的查询转换,有称为查询改写,指oracle在执行目标sql时可能会做等价改写,目的是为了更高效的执行目标sql 在10g及其以后的版本中,oracle会对 ...

  4. python学习笔记(四):函数

    一.函数是什么? 函数一词来源于数学,但编程中的「函数」概念,与数学中的函数是有很大不同的,编程中的函数在英文中也有很多不同的叫法.在BASIC中叫做subroutine(子过程或子程序),在Pasc ...

  5. jQ版大图滚动

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  6. apache 不解析 php

    apache 不解析php 1.找到: AddType application/x-gzip .gz .tgz在其下面添加: AddType application/x-httpd-php .php ...

  7. leetcode669

    本题目是使用递归处理,根据当前的值来判断剪去的子树,保留剩下的子树. class Solution { public: TreeNode* trimBST(TreeNode* root, int L, ...

  8. delphi 天气预报

    天气预报 var astream : tmemorystream; sStream : TStringStream; jv : TJSONValue; begin astream := tmemory ...

  9. 1.forEach():遍历数组,并为每个元素调用传入的函数; 举例:

    var a = [1,2,3]; var sum = 0; //传一个参数 a.forEach(function(v){ sum += v; }); console.log(sum);//6 //传三 ...

  10. 迷你MVVM框架 avalonjs 0.99发布

    在本版本主要是性能优化,添加一些有用的功能(如回调什么的),离成品阶段不远了. 修正 updateViewModel bug 修正监控数组的set方法 bug 添加data-each-rendered ...