hdu 5724 Chess 博弈sg+状态压缩
Chess
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
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.
1
2 19 20
2
1 19
1 18
YES
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define LL __int64
#define pi (4*atan(1.0))
#define eps 1e-8
#define bug(x) cout<<"bug"<<x<<endl;
const int N=3e6+,M=1e6+,inf=1e9+;
const LL INF=1e18+,mod=1e9+; int sg[N];
int dfs(int n)
{
if(sg[n]!=-)return sg[n];
int flag[],nex[], mex[];
for(int i=;i<;i++)
flag[i]=,mex[i]=,nex[i]=;Q
for(int i=;i<;i++)
if(n&(<<i))flag[i]=;
nex[]=;
for(int i=;i>=;i--)
if(!flag[i+])nex[i]=i+;
else nex[i]=nex[i+];
for(int i=;i<;i++)
{
if(flag[i]&&nex[i]<)
{
int z=n-(<<i)+(<<nex[i]);
//cout<<z<<endl;
dfs(z);
mex[sg[z]]=;
}
}
for(int i=;;i++)
if(!mex[i])return sg[n]=i;
}
int main()
{ memset(sg,-,sizeof(sg));
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
int ans=;
for(int i=;i<=n;i++)
{
int m,sum=;
scanf("%d",&m);
for(int j=;j<=m;j++)
{
int x;
scanf("%d",&x);x--;
sum+=(<<x);
}
ans^=dfs(sum);
}
if(ans)printf("YES\n");
else printf("NO\n");
}
return ;
}
hdu 5724 Chess 博弈sg+状态压缩的更多相关文章
- HDU 5724 Chess(SG函数+状态压缩)
http://acm.split.hdu.edu.cn/showproblem.php?pid=5724 题意: 现在有一个n*20的棋盘,上面有一些棋子,双方每次可以选择一个棋子把它移动到其右边第一 ...
- HDU 5724 Chess (sg函数)
Chess 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5724 Description Alice and Bob are playing a s ...
- HDU 5724 Chess(SG函数)
Chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- hdu 5724 Chess 博弈
题目链接 一个n行20列的棋盘. 每一行有若干个棋子. 两人轮流操作, 每人每次可以将一个棋子向右移动一个位置, 如果它右边有一个棋子, 就跳过这个棋子, 如果有若干个棋子, 就将这若干个都跳过. 但 ...
- hdu 5724 SG+状态压缩
Chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- HDU 5724 Chess(国际象棋)
HDU 5724 Chess(国际象棋) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- hdu 5025 Saving Tang Monk 状态压缩dp+广搜
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4092939.html 题目链接:hdu 5025 Saving Tang Monk 状态压缩 ...
- HDU 5724 Chess (状态压缩sg函数博弈) 2016杭电多校联合第一场
题目:传送门. 题意:有n行,每行最多20个棋子,对于一个棋子来说,如果他右面没有棋子,可以移动到他右面:如果有棋子,就跳过这些棋子移动到后面的空格,不能移动的人输. 题解:状态压缩博弈,对于一行2^ ...
- HDU 5724 Chess(博弈论)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5724 [题目大意] 给出一个n行,每行有20格的棋盘,棋盘上有一些棋子,每次操作可以选择其中一个棋 ...
随机推荐
- 算法训练 P0505
一个整数n的阶乘可以写成n!,它表示从1到n这n个整数的乘积.阶乘的增长速度非常快,例如,13!就已经比较大了,已经无法存放在一个整型变量中:而35!就更大了,它已经无法存放在一个浮点型变量中.因此, ...
- AtCoder Beginner Contest 084(AB)
A - New Year 题目链接:https://abc084.contest.atcoder.jp/tasks/abc084_a Time limit : 2sec / Memory limit ...
- php+redis,延迟任务 实现自动取消订单,自动完成订单
简单定时任务解决方案:使用redis的keyspace notifications(键失效后通知事件) 需要注意此功能是在redis 2.8版本以后推出的,因此你服务器上的reids最少要是2.8版本 ...
- django 表单常用field
BooleanField字段:相当于单选框 CharField:接受字符串 参数:max_length最大长度,min_length最小长度 require字段是否是必须的,默认为required=T ...
- python静态属性@property、类方法@classmethod、静态方法@staticmethod和普通方法
静态属性:即将类的函数通过@property属性封装,封装后实例调用该函数时,不再需要在函数后面加(),而是用类似调用数据属性的方式直接调用函数名称即可执行函数. 静态属性既可以访问类的属性,也可以访 ...
- 4、pandas的数据筛选之isin和str.contains函数
DataFrame列表: 以>,<,==,>=,<=来进行选择(“等于”一定是用‘==’,如果用‘=’就不是判断大小了): 使用 &(且) 和 |(或) 时每个条件都要 ...
- Linux下的查找技巧
Find知识点: -mtime ——修改时间 -ctime ——创建时间 -atime ——访问时间 mtime 举例说明: -mtime n : n为数字,意思为在n天之前的“一天之内”被更改过内容 ...
- Adobe阅读器渗透攻击
Adobe阅读器渗透攻击 实验前准备 1.两台虚拟机,其中一台为kali,一台为windows xp sp3(老师给的xp虚拟机winxpAttaker,密码:mima1234). 2.设置虚拟机网络 ...
- 盒子总结,文本属性操作,reset操作,高级选择器,高级选择器优先级,边界圆角(了解),a标签的四大伪类,背景图片操作,背景图片之精灵图
盒子总结 ''' block: 设置宽高 1.没有设置宽,宽自适应父级的宽(子级的border+padding+width=父级的width) 2.没有设置高,高由内容撑开 设置了宽高 一定采用设置的 ...
- 尚硅谷面试第一季-11MyBatis中当实体类中的属性名和表中的字段名不一样怎么办
问题: MyBatis中当实体类中的属性名和表中的字段名不一样 ,怎么办 ? 解决方案: 1.写sql语句时起别名 <!-- id属性:必须是接口中方法的方法名 resultType属性:必须是 ...