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格的棋盘,棋盘上有一些棋子,每次操作可以选择其中一个棋 ...
随机推荐
- [转载]decode()函数简介
今天看别人的SQL时看这里面还有decode()函数,以前从来没接触到,上网查了一下,还挺好用的一个函数,写下来希望对朋友们有帮助哈! decode()函数简介: 主要作用:将查询结果翻译成其他值(即 ...
- 前端页面报net::ERR_CONNECTION_RESET错误的原因
本机和测试环境都是OK的.但是一到线上就报错:可能原因总结如下: 1 可能是服务器限制了文件上传的权限. 解决方法:开通了文件上传权限. 2 也许导致这种错误的方式有很多,可能是因为post请求时提交 ...
- window bat 运行 cmd 命令
新建一个.bat批处理文件,编写以下切换目录 并且执行 ipconfig 命令: cmd /k "cd /d D:phpStudy/WWW & ipconfig" cmd ...
- git获取一个版本相对于另一个版本新增,修改,删除的文件
git diff --name-status 00ef237ef0f0a4b8bd9609c2b6d570472028212d abf13b4d58abbb05a7d494cdc205d025978a ...
- docker 初步使用
CentOS Linux release 7.2.1511 Docker version 17.03.1-ce 安装与启动 yum直接安装的docker版本较低,推荐这样安装: # 官方,可能网络连不 ...
- 02: docker高级篇
1.1 Docker Compose 1.Docker Compose 介绍 1. Compose是一个定义和管理多容器的工具,使用Python语言编写. 2. 使用Compose配置文件描述多个容器 ...
- 自动发现实现url+响应时间监控
url自动发现脚本: [root@jenkins scripts]# cat urlDiscovery.py #!/usr/bin/env python #coding:utf-8 import o ...
- javascript 点击按钮实现隐藏显示切换效果
原文链接:http://www.jb51.net/article/79083.htm <html> <head> <meta charset="gb2312&q ...
- 剑指offer(31)1~n整数中1出现的次数
题目描述 求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1.10.11.12.13因此共出现6次,但是对于后面问题他就没辙了. ...
- topcoder srm 525 div1
problem1 link 最后剩下的是中间的一个矩形.所以可以直接枚举这个矩形,如果它含有的硬币个数等于$K$,则再计算移动的最少次数,更新答案. problem2 link 首先,每个节点发送每种 ...