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. 如何用纯 CSS 创作一种侧立图书的特效

    效果预览 在线演示 按下右侧的"点击预览"按钮在当前页面预览,点击链接全屏预览. https://codepen.io/zhang-ou/pen/deVgRM 可交互视频教程 此视 ...

  2. HTML5表单新增元素与属性

    form属性 在html4中,表单的从属元素必须写在表单内部,而在HTML5中,可以把他们书写在任何地方,然后为该元素指定一个form属性,属性值为该表单的id,这样就可以声明该元素从属于指定表单了. ...

  3. (二)Robto Framewoek使用自己的python库

    有时候找不到合适的库来完成自动化工作,则需要使用自己定义的python库.本文简单描述自建python库,以及在robotframework中的使用方法. 新建库目录 在C:\Python27\Lib ...

  4. php file_get_contents json_decode 输出为NULL

    解决办法一:不小心在返回的json字符串中返回了BOM头的不可见字符,某些编辑器默认会加上BOM头,如下处理才能正确解析json数据: $info = json_decode(trim($info,c ...

  5. javascript:与获取鼠标位置有关的属性

    javascript并没有mouse对象,获取鼠标坐标要靠强大的event对象。 我们通过监听document的mousemove,就可以实时获得鼠标位置。 但是!!event中和鼠标相关的属性太多了 ...

  6. HDU1754-I Hate It,线段数水题~~2016.4.11

    I Hate It                                                                                           ...

  7. [Kubernetes]Volume

    容器技术使用rootfs机制和Mount Namespace,构建出一个同宿主机完全隔离开的文件系统环境 那容器里进程新建的文件,怎么样才能让宿主机获取到?宿主机上的文件和目录,怎么样才能让容器里的进 ...

  8. rsync 同步文件重复拷贝问题

    rsync 是同步文件的利器,一般用于多个机器之间的文件同步与备份,同时也支持在本地的不同目录之间互相同步文件.在这种场景下,rsync 远比 cp 命令更加合适,它只会同步需要更新的文件,默认情况下 ...

  9. P1359 租用游艇 洛谷

    https://www.luogu.org/problem/show?pid=1359 题目描述 长江游艇俱乐部在长江上设置了n 个游艇出租站1,2,…,n.游客可在这些游艇出租站租用游艇,并在下游的 ...

  10. POJ 3281 [网络流dinic算法模板]

    题意: 农场主有f种食物,d种饮料,n头牛. 接下来的n行每行第一个数代表第i头牛喜欢吃的食物数量,和第i头牛喜欢喝的饮料数目. 接下来分别是喜欢的食物和饮料的编号. 求解:农场主最多能保证几头牛同时 ...