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局游戏. 每局游戏开始有一个空串,然后双方轮流给这个串的末尾添 ...
随机推荐
- 《算法导论》 — Chapter 8 线性时间排序
序 到目前为止,关于排序的问题,前面已经介绍了很多,从插入排序.合并排序.堆排序以及快速排序,每一种都有其适用的情况,在时间和空间复杂度上各有优势.它们都有一个相同的特点,以上所有排序的结果序列,各个 ...
- 【51nod 1092】 回文字符串(区间DP)
回文串是指aba.abba.cccbccc.aaaa这种左右对称的字符串.每个字符串都可以通过向中间添加一些字符,使之变为回文字符串. 例如:abbc 添加2个字符可以变为 acbbca,也可以添加3 ...
- NYOJ-676小明的求助,快速幂求模,快速幂核心代码;
小明的求助 时间限制:2000 ms | 内存限制:65535 KB 难度:2 描述 小明对数学很有兴趣,今天老师出了道作业题,让他求整数N的后M位,他瞬间感觉老师在作弄他,因为这是so easy ...
- Auto-Scaling Web Applications in Clouds: A Taxonomy and Survey读书笔记
这篇文章是发在2018年CSUR上的一篇文章,主要是讲虚拟机上web应用的auto-scaling技术的分类 近年来许多web 应用服务商将他们的应用迁移到云数据中心,为什么要迁移到云上呢?其中一个重 ...
- 【树形DP】codeforces K. Send the Fool Further! (medium)
http://codeforces.com/contest/802/problem/K [题意] 给定一棵树,Heidi从根结点0出发沿着边走,每个结点最多经过k次,求这棵树的最大花费是多少(同一条边 ...
- hdu 2167 状态压缩
/*与1565的解法差不多*/ #include<stdio.h> #include<string.h> int map[16][16]; int dp[2][1<< ...
- CF788E:New task
n个数字中,每个数有数字A和属性B,每次操作将某个点x的属性B改变为0或1,求满足这样要求的子序列的个数: 下标a<b<c<d<e,而Aa<=Ab=Ac=Ad>=A ...
- [JSP]自定义EL函数以及使用
有时候在JSP页面需要进行一连串的字符串的处理,需要进行自定义EL函数. 先看EL函数的tld文件: standard.jar下面: 自定义EL函数: 1.编写EL函数(全是public static ...
- MySql数据库导出csv文件命令
MySql数据库导出csv文件命令: MySql数据库导出csv文件命令: mysql> select first_name,last_name,email from account into ...
- Eventquery.vbs
https://docs.microsoft.com/en-us/previous-versions/orphan-topics/ws.10/cc772995(v=ws.10)