Codeforces 768 E. Game of Stones 博弈DP
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.
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.
Print a single line containing "YES" (without quotes) if Jon wins, otherwise print "NO" (without quotes)
1
5
NO
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的更多相关文章
- Codeforces 538E Demiurges Play Again(博弈DP)
http://codeforces.com/problemset/problem/538/E 题目大意: 给出一棵树,叶子节点上都有一个值,从1-m.有两个人交替从根选择道路,先手希望到达的叶子节点尽 ...
- Codeforces 219D. Choosing Capital for Treeland (树dp)
题目链接:http://codeforces.com/contest/219/problem/D 树dp //#pragma comment(linker, "/STACK:10240000 ...
- HDU 5623 KK's Number (博弈DP)
KK's Number 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/K Description Our lovely KK h ...
- 博弈dp 以I Love this Game! POJ - 1678 为例
写在前面的话 知识基础:一些基础的博弈论的方法,动态规划的一些知识 前言:博弈论就是一些关于策略或者游戏之间的最优解,动态规划就是对于一些状态之间转移的一些递推式(or 递归),dp分为很多很多种,比 ...
- [CodeForces - 1272D] Remove One Element 【线性dp】
[CodeForces - 1272D] Remove One Element [线性dp] 标签:题解 codeforces题解 dp 线性dp 题目描述 Time limit 2000 ms Me ...
- 博弈dp入门 POJ - 1678 HDU - 4597
本来博弈还没怎么搞懂,又和dp搞上了,哇,这真是冰火两重天,爽哉妙哉. 我自己的理解就是,博弈dp有点像对抗搜索的意思,但并不是对抗搜索,因为它是像博弈一样,大多数以当前的操作者来dp,光想是想不通的 ...
- codeforces 768 D. Jon and Orbs(概率dp)
题目链接:http://codeforces.com/contest/768/problem/D 题意:一共有k种球,要得到k种不同的球至少一个,q个提问每次提问给出一个数pi,问概率大小大于等于pi ...
- Codeforces Round #222 (Div. 1) 博弈 + dp
一般这种要倒着来. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #def ...
- Codeforces 455B A Lot of Games:博弈dp【多局游戏】
题目链接:http://codeforces.com/problemset/problem/455/B 题意: 给你n个字符串,然后进行k局游戏. 每局游戏开始有一个空串,然后双方轮流给这个串的末尾添 ...
随机推荐
- Python之 七级字典查询
# -*- coding:utf- -*- # 作业要求: # 打印直辖市,省,市,县,区,街道五级菜单: # 可以一层一层地进入到所有层 # 可以退出到上一层 # 可随时退出程序 mapChina ...
- uC/OSii之任务划分
满足以下几个指标将会使软件设计比较简洁高效. 满足实时性指标 任务数目合理 简化软件系统 降低资源需求 设备依赖性划分:主要是对于一些输入输出设备进行划分,输入输出设备分为主动型和被动性.主动型有一个 ...
- LeetCode01--寻找两个有序数组的中位数
''' 给定两个大小为 m 和 n 的有序数组 nums1 和 nums2. 请你找出这两个有序数组的中位数,并且要求算法的时间复杂度为 O(log(m + n)). 你可以假设 nums1 和 nu ...
- 3.3.2 使用 cut 选定字段
cut 命令是用来剪下文本文件里的数据,文本文件可以是字段类型或是字符类型.后一种数据类型在遇到需要从文件里剪下特定的列时,特别方便.请注意:一个制表字符在此被视为单个字符. ...
- 类函数调用与this指针
1.定义多个对象是,C++编译器只分配一段空间存放公共的函数代码段,调用各个对象的函数时,都调用这个公共的代码片段. 每个对象的存储空间只是包含该对象数据成员所占的空间,函数代码存储在对象空间之外. ...
- HDU 3911 区间合并求最大长度的问题
http://vjudge.net/problem/viewProblem.action?id=21557 题目大意: 每进行一次颜色改变都可以把一段区间内的黑石头变成白石头,白石头变成黑石头,最后问 ...
- bzoj3572[Hnoi2014] 世界树 虚树+dp+倍增
[Hnoi2014]世界树 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 1921 Solved: 1019[Submit][Status][Dis ...
- SeLion数据驱动中遇到的问题,以及解决方案
问题描述: 使用selion框架数据驱动时,总是test ignored. 解决方案: 把这个dataprovider方法拿出来做单元测试.有详细报错. 问题1:使用wps保存,poi包只能解析xls ...
- Postman调试依赖登录接口的3种方法
在接口测试种, 我们经常会遇到有些接口登录后才能访问.我们在使用Postman调试这种接口时一般有3种方法: 依次请求 如果有登录接口的文档,或者通过抓包比较容易抓出登录请求的参数和格式,可以先使用P ...
- Codeforces Round #294 (Div. 2) D. A and B and Interesting Substrings [dp 前缀和 ]
传送门 D. A and B and Interesting Substrings time limit per test 2 seconds memory limit per test 256 me ...