Chess

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

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
 
Author
HIT
 
Source
  1. #pragma comment(linker, "/STACK:1024000000,1024000000")
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<cmath>
  5. #include<string>
  6. #include<queue>
  7. #include<algorithm>
  8. #include<stack>
  9. #include<cstring>
  10. #include<vector>
  11. #include<list>
  12. #include<set>
  13. #include<map>
  14. using namespace std;
  15. #define LL __int64
  16. #define pi (4*atan(1.0))
  17. #define eps 1e-8
  18. #define bug(x) cout<<"bug"<<x<<endl;
  19. const int N=3e6+,M=1e6+,inf=1e9+;
  20. const LL INF=1e18+,mod=1e9+;
  21.  
  22. int sg[N];
  23. int dfs(int n)
  24. {
  25. if(sg[n]!=-)return sg[n];
  26. int flag[],nex[], mex[];
  27. for(int i=;i<;i++)
  28. flag[i]=,mex[i]=,nex[i]=;Q
  29. for(int i=;i<;i++)
  30. if(n&(<<i))flag[i]=;
  31. nex[]=;
  32. for(int i=;i>=;i--)
  33. if(!flag[i+])nex[i]=i+;
  34. else nex[i]=nex[i+];
  35. for(int i=;i<;i++)
  36. {
  37. if(flag[i]&&nex[i]<)
  38. {
  39. int z=n-(<<i)+(<<nex[i]);
  40. //cout<<z<<endl;
  41. dfs(z);
  42. mex[sg[z]]=;
  43. }
  44. }
  45. for(int i=;;i++)
  46. if(!mex[i])return sg[n]=i;
  47. }
  48. int main()
  49. {
  50.  
  51. memset(sg,-,sizeof(sg));
  52. int T;
  53. scanf("%d",&T);
  54. while(T--)
  55. {
  56. int n;
  57. scanf("%d",&n);
  58. int ans=;
  59. for(int i=;i<=n;i++)
  60. {
  61. int m,sum=;
  62. scanf("%d",&m);
  63. for(int j=;j<=m;j++)
  64. {
  65. int x;
  66. scanf("%d",&x);x--;
  67. sum+=(<<x);
  68. }
  69. ans^=dfs(sum);
  70. }
  71. if(ans)printf("YES\n");
  72. else printf("NO\n");
  73. }
  74. return ;
  75. }

hdu 5724 Chess 博弈sg+状态压缩的更多相关文章

  1. HDU 5724 Chess(SG函数+状态压缩)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=5724 题意: 现在有一个n*20的棋盘,上面有一些棋子,双方每次可以选择一个棋子把它移动到其右边第一 ...

  2. HDU 5724 Chess (sg函数)

    Chess 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5724 Description Alice and Bob are playing a s ...

  3. HDU 5724 Chess(SG函数)

    Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  4. hdu 5724 Chess 博弈

    题目链接 一个n行20列的棋盘. 每一行有若干个棋子. 两人轮流操作, 每人每次可以将一个棋子向右移动一个位置, 如果它右边有一个棋子, 就跳过这个棋子, 如果有若干个棋子, 就将这若干个都跳过. 但 ...

  5. hdu 5724 SG+状态压缩

    Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  6. HDU 5724 Chess(国际象棋)

    HDU 5724 Chess(国际象棋) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  7. hdu 5025 Saving Tang Monk 状态压缩dp+广搜

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092939.html 题目链接:hdu 5025 Saving Tang Monk 状态压缩 ...

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

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

  9. HDU 5724 Chess(博弈论)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5724 [题目大意] 给出一个n行,每行有20格的棋盘,棋盘上有一些棋子,每次操作可以选择其中一个棋 ...

随机推荐

  1. [转载]Oracle ltrim() 函数用法

    前面有说到过LPAD和RPAD这两个函数用法的文章,今天发现与之相反意义的另外两个函数,那就是LTRIM() RTRIM(). 这次就挑LTRIM() 这一函数来讲讲: 具体的语法格式如下: LTRI ...

  2. C++ for循环与迭代器

    1.基本的for循环 std::vector<int> arr; ... for(std::vector<int>::iterator it=arr.begin();it!=a ...

  3. 【react】兄弟组件的通信方式,传统非redux

    很多用过redux开发的朋友们都知道,一般兄弟组件通信可以使用redux. redux也是近期在挤时间学习中.可能也不是很懂,说不定是有错误的理解,若有.现在虽然自己搭建了一个react+router ...

  4. USB设备被识别流程

    源:   USB设备被识别流程

  5. jquery photoClip支持手机端,PC端 本地裁剪图片后上传插件

    支持手机,PC最好的是jquery photoClip插件,下载地址&示例:https://github.com/topoadmin/photoClip demo.html 代码: <! ...

  6. elasticsearch配置文件详解

    来自:http://www.searchtech.pro/articles/2013/02/18/1361194291548.html elasticsearch的config文件夹里面有两个配置文 ...

  7. node.js 初学(二)—— 搭建注册/登录服务器

    node.js 初学(二)—— 搭建注册/登录服务器 理论上来说,代码实现在理论和实际上是一样的.但实际上来说,他们不是 做一个最简单的用户注册登录功能 1.接口定义: 注册:/user?act=re ...

  8. thiniphp tp5 使用缓存

    在应用或者模块配置文件中配置好所用缓存的类型及相关参数: 如果是文件类型可以用 'cache' => [ 'type' => 'File', 'path' => CACHE_PATH ...

  9. webpack对于引入的模块无法智能代码提示

    前端模块太多了,模块里的方法比较难记住,所以我们一般靠的都是IDE的代码提示. 但是有时候我们会发现对于引入的模块没有代码提示,我也安装了模块呀,为什么没有代码提示? 主要是package.json的 ...

  10. 使用Http协议Post上传文件

    转载:http://www.cnblogs.com/softidea/p/5745369.html 转载:https://blog.csdn.net/huanongying131/article/de ...