Chess

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1821    Accepted Submission(s): 799

Problem Description
Alice and Bob are playing a special chess game on an n × 20 chessboard. There are several chesses on the chessboard. They can move one chess in one turn. If there are no other chesses on the right adjacent block of the moved chess, move the chess to its right adjacent block. Otherwise, skip over these chesses and move to the right adjacent block of them. Two chesses can’t be placed at one block and no chess can be placed out of the chessboard. When someone can’t move any chess during his/her turn, he/she will lose the game. Alice always take the first turn. Both Alice and Bob will play the game with the best strategy. Alice wants to know if she can win the game.
 
Input
Multiple test cases.

The first line contains an integer T(T≤100), indicates the number of test cases.

For each test case, the first line contains a single integer n(n≤1000), the number of lines of chessboard.

Then n lines, the first integer of ith line is m(m≤20), indicates the number of chesses on the ith line of the chessboard. Then m integers pj(1≤pj≤20) followed, the position of each chess.

 
Output
For each test case, output one line of “YES” if Alice can win the game, “NO” otherwise.
 
Sample Input
2
1
2 19 20
2
1 19
1 18
 
Sample Output
NO
YES
/*
hdu 5724 SG+状态压缩 感觉上是博弈,而且很久以前就看了看SG,但是并没怎么系统地去学习zzz。
首先可以把棋盘n行看成n个石碓,用1表示有棋子,0表示没有的话,能够用二进制表示出所有的状态:
1000100这个可以转换成 0100100 1000010等等 然后就能利用公式求出每种情况的SG(枚举 1~(1<<20))
得出每一行的状态计算即可 hhh-2016-08-01 17:28:17
学习:
//http://blog.csdn.net/luomingjun12315/article/details/45555495
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
using namespace std;
#define lson (i<<1)
#define rson ((i<<1)|1)
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f;
const int maxn = 1000100; int vis[22];
int sg[1<<20]; int SG(int cur)
{
memset(vis,0,sizeof(vis));
for(int i = 20; i >= 0; i--)
{
if(cur & (1<<i))
{
for(int j = i-1; j >= 0; j--)
{
if(!(cur & (1 << j)))
{
int tmp = cur;
tmp ^= ((1<<i)^(1<<j));
vis[sg[tmp]] = true;
break;
}
}
}
}
for(int i = 0 ; i <= 20; i++)
{
if(!vis[i])
return i;
}
return 0;
} int main()
{
memset(sg,0,sizeof(sg));
for(int i = 1; i < (1 << 20); i++)
sg[i] = SG(i);
int T,n,x;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
int ans = 0;
for(int i = 1;i <= n;i++)
{
int m,cur = 0;
scanf("%d",&m);
for(int j = 1;j <= m;j++)
{
scanf("%d",&x);
cur |= 1 << (20-x);
}
ans ^= sg[cur];
}
if(ans )
printf("YES\n");
else
printf("NO\n");
}
return 0;
}

  

hdu 5724 SG+状态压缩的更多相关文章

  1. HDU 5724 Chess (状态压缩sg函数博弈) 2016杭电多校联合第一场

    题目:传送门. 题意:有n行,每行最多20个棋子,对于一个棋子来说,如果他右面没有棋子,可以移动到他右面:如果有棋子,就跳过这些棋子移动到后面的空格,不能移动的人输. 题解:状态压缩博弈,对于一行2^ ...

  2. hdu 5094 Maze 状态压缩dp+广搜

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092176.html 题目链接:hdu 5094 Maze 状态压缩dp+广搜 使用广度优先 ...

  3. hdu 4272 LianLianKan 状态压缩

      LianLianKan Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  4. hdu 1429(bfs+状态压缩)

    题意:容易理解,但要注意的地方是:如果魔王回来的时候刚好走到出口或还未到出口都算逃亡失败.因为这里我贡献了一次wa. 分析:仔细阅读题目之后,会发现最多的钥匙数量为10把,所以把这个作为题目的突破口, ...

  5. hdu 2489 最小生成树状态压缩枚举

    思路: 直接状态压缩暴力枚举 #include<iostream> #include<algorithm> #include<cstdio> #include< ...

  6. LianLianKan - HDU 4272(状态压缩)

    题目大意:有一列数据,可以从最上面的开始连接下面相同的元素,然后消除,不过距离不能超过6,询问最后能不能消除完整个数列. 分析:首先讨论一点最远能消除的地方,比如点的位置是x,如若想要消除x+1位置处 ...

  7. HDU 3001(状态压缩dp)

    状态压缩dp的第一题! 题意:Mr ACMer想要进行一次旅行,他决定访问n座城市.Mr ACMer 可以从任意城市出发,必须访问所有的城市至少一次,并且任何一个城市访问的次数不能超过2次.n座城市间 ...

  8. hdu 4856 Tunnels 状态压缩dp

    Tunnels Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem ...

  9. HDU 1074 (DP + 状态压缩)

    题意: 给你N个课程, 每个课程有结束的时间 , 和完成这门课程需要的时间 超过课程结束ed时间,每一天就要花费 1点绩点: 然后要求你安排如何做课程使得花费的绩点最少 (看了博客后才发现状态压缩很⑥ ...

随机推荐

  1. 团队作业7——第二次项目冲刺(Beta版本12.08)

    项目每个成员的进展.存在问题.接下来两天的安排. 已完成的内容:完成了排行榜的测试.上传头像功能的原型设计.界面优化 计划完成的内容:上传头像功能开发.测试.头像裁剪原型设计 每个人的工作 (有wor ...

  2. [SDOI2014]旅行

    洛谷 P3313 [SDOI2014]旅行 https://www.luogu.org/problem/show?pid=3313 题目描述 S国有N个城市,编号从1到N.城市间用N-1条双向道路连接 ...

  3. nyoj 概率计算

    概率计算 时间限制:1000 ms  |  内存限制:65535 KB 难度:1   描述 A和B两个人参加一场答题比赛.比赛的过程大概是A和B两个人轮流答题,A先答.一旦某人没有正确回答问题,则对手 ...

  4. NFC驱动调试

    1.NFC基本概念: NFC 又称为近场通信,是一种新兴技术,可以在彼此靠近的情况下进行数据交换,是由非接触式射频识别(RFID) 及互连互通技术整合演变而来,通过单一芯片集成感应式读卡器: NFC有 ...

  5. prop attr 到底哪里不一样?

    好吧 首先承认错误  说好的每天进行一次只是总结  但是我没坚持住 准确的来说 我并没有每天会学到了东西 但是 我一直在持续努力着  以后应该不会每天都写  但是自己觉得有用的  或者想加强记忆的 可 ...

  6. monog和github学习

    1.导出服务器数据库到本地以json的格式储存:mongoexport -h ip -d dbname -c user -o D:\mondb\user.json2.导入本地Json到本地项目中:D: ...

  7. js 中bind

    function fn(a){ this.innerHTML = a; console.log(this); } //fn("hello"); span1.onclick =fun ...

  8. ASP.NET 访问项目网站以外的目录文件

    简单的说,可以通过在 IIS 添加虚拟目录的方法做到,获取访问路径的时候就用 HttpContext.Current.Server.MapPath("~/xxx"); 的方式. 下 ...

  9. 爬虫必备 User-Agent 列表

    USER_AGENTS = [ "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; AcooBrowser; .NET CLR ...

  10. 数据结构 Python实现

    参考博客:浅谈算法和数据结构: 一 栈和队列   Python数据结构--栈.队列的实现(一)    Python数据结构--栈.队列的实现(二)    Python数据结构--链表的实现 数据结构 ...