E. Game of Stones
 

Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple:

  • The game starts with n piles of stones indexed from 1 to n. The i-th pile contains si stones.
  • The players make their moves alternatively. A move is considered as removal of some number of stones from a pile. Removal of 0stones does not count as a move.
  • The player who is unable to make a move loses.

Now Jon believes that he is ready for battle, but Sam does not think so. To prove his argument, Sam suggested that they play a modified version of the game.

In this modified version, no move can be made more than once on a pile. For example, if 4 stones are removed from a pile, 4 stones cannot be removed from that pile again.

Sam sets up the game and makes the first move. Jon believes that Sam is just trying to prevent him from going to battle. Jon wants to know if he can win if both play optimally.

Input
 

First line consists of a single integer n (1 ≤ n ≤ 106) — the number of piles.

Each of next n lines contains an integer si (1 ≤ si ≤ 60) — the number of stones in i-th pile.

Output

Print a single line containing "YES" (without quotes) if Jon wins, otherwise print "NO" (without quotes)

Examples
input
1
5
output
NO
Note

In the first case, Sam removes all the stones and Jon loses.

In second case, the following moves are possible by Sam: 

In each of these cases, last move can be made by Jon to win the game as follows: 

 题意:

  一堆石子,一开始你可以拿走任意个,假设拿走k(k>=1)个,那么另外一个人就不能再拿k个了

  现在有n堆石子,两人轮流拿,不能拿的时候那个人就输了

问后手是否能赢

题解:

  石子最多60颗,1<<60,状态压缩跑sg函数

#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<LL,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18;
const double Pi = acos(-1.0);
const int N = 1e6+, maxn = 1e3+, mod = 1e9+, inf = 2e9; map<LL,int > dp[N];
int sg[N],n;
int dfs(int x,LL dep) {
if(dp[x].count(dep)) return dp[x][dep];
LL ret = ;
for(int i = ; i < x; ++i) {
if(((dep>>i)&) == ) {
ret |= <<(dfs(x-i-,dep|(<<i)));
}
}
for(int i = ; i < ; ++i) {
if((ret>>i&) == ) {
dp[x][dep] = i;
break;
}
}
return dp[x][dep];
}
int main() {
for(int i = ; i <= ; ++i) sg[i] = dfs(i,);
scanf("%d",&n);
int ans = ;
for(int i = ; i <= n; ++i) {
int x;
scanf("%d",&x);
ans ^= sg[x];
}
if(!ans) puts("YES");
else puts("NO");
return ;
}

Codeforces 768 E. Game of Stones 博弈DP的更多相关文章

  1. Codeforces 538E Demiurges Play Again(博弈DP)

    http://codeforces.com/problemset/problem/538/E 题目大意: 给出一棵树,叶子节点上都有一个值,从1-m.有两个人交替从根选择道路,先手希望到达的叶子节点尽 ...

  2. Codeforces 219D. Choosing Capital for Treeland (树dp)

    题目链接:http://codeforces.com/contest/219/problem/D 树dp //#pragma comment(linker, "/STACK:10240000 ...

  3. HDU 5623 KK's Number (博弈DP)

    KK's Number 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/K Description Our lovely KK h ...

  4. 博弈dp 以I Love this Game! POJ - 1678 为例

    写在前面的话 知识基础:一些基础的博弈论的方法,动态规划的一些知识 前言:博弈论就是一些关于策略或者游戏之间的最优解,动态规划就是对于一些状态之间转移的一些递推式(or 递归),dp分为很多很多种,比 ...

  5. [CodeForces - 1272D] Remove One Element 【线性dp】

    [CodeForces - 1272D] Remove One Element [线性dp] 标签:题解 codeforces题解 dp 线性dp 题目描述 Time limit 2000 ms Me ...

  6. 博弈dp入门 POJ - 1678 HDU - 4597

    本来博弈还没怎么搞懂,又和dp搞上了,哇,这真是冰火两重天,爽哉妙哉. 我自己的理解就是,博弈dp有点像对抗搜索的意思,但并不是对抗搜索,因为它是像博弈一样,大多数以当前的操作者来dp,光想是想不通的 ...

  7. codeforces 768 D. Jon and Orbs(概率dp)

    题目链接:http://codeforces.com/contest/768/problem/D 题意:一共有k种球,要得到k种不同的球至少一个,q个提问每次提问给出一个数pi,问概率大小大于等于pi ...

  8. Codeforces Round #222 (Div. 1) 博弈 + dp

    一般这种要倒着来. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #def ...

  9. Codeforces 455B A Lot of Games:博弈dp【多局游戏】

    题目链接:http://codeforces.com/problemset/problem/455/B 题意: 给你n个字符串,然后进行k局游戏. 每局游戏开始有一个空串,然后双方轮流给这个串的末尾添 ...

随机推荐

  1. 第一章:systemverilog简介

    1.为何要学systemverilog ..... 2.systemverilog起源 ..... 3.systemverilog标准历程 systemverilog3.0 for 综合 system ...

  2. mysql EXPLAIN Join Types 手册解释 及数据实操

     第一部分:名称解释 文档地址 https://dev.mysql.com/doc/refman/5.7/en/explain-output.html EXPLAIN Join Types: The ...

  3. Mac OS X 上如何切换默认的 Python 版本?

  4. Java有几种线程池?

    Java通过Executors提供四种线程池,分别为:newCachedThreadPool创建一个可缓存线程池,如果线程池长度超过处理需要,可灵活回收空闲线程,若无可回收,则新建线程newFixed ...

  5. Reactor和Proactor模式的讲解(关于异步,同步,阻塞与非阻塞)

    在高性能的I/O设计中,有两个比较著名的模式Reactor和Proactor模式,其中Reactor模式用于同步I/O,而Proactor运用于异步I/O操作. 在比较这两个模式之前,我们首先的搞明白 ...

  6. HashMap排序的问题

    那么已知一个HashMap<Integer,User>集合, User有name(String)和 age(int)属性.请写一个方法实现对HashMap 的排序功能,该方法接收 Hash ...

  7. 转 Linux里设置环境变量的方法(export PATH)

    1.动态库路径的设置 Linux下调用动态库和windows不一样.linux 可执行程序是靠配置文件去读取路径的,因此有些时候需要设置路径 具体操作如下export LD_LIBRARY_PATH= ...

  8. Tomcat可以实现Session共享方案

    说明:原来Tomcat也是可以实现Session共享的,这样大大减少的硬编码的实现,并且前面用Nginx分流时不用考虑Session的问题,因为是Web容器提供了Session共享的支持. 1.在每个 ...

  9. 框架-弹出选择框(Jquery传递Json数组)

    给一个button按钮,执行方法 Json传值$("body").on("click", "#btnsure", function() {  ...

  10. Intellij IDEA远程调试tomcat

    1.windows系统 文件catalina.bat首行增加下面代码 set CATALINA_OPTS=-server -Xdebug -Xnoagent -Djava.compiler=NONE ...