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格的棋盘,棋盘上有一些棋子,每次操作可以选择其中一个棋 ...
随机推荐
- ui-router .state参数配置
.state('页面被引用时的变量名',{ template: '<h1>My Contacts</h1>',//被应用时插入的模板,状态被激活时,它的模板会自动插入到父状态对 ...
- 为什么List.add()所增加的数据都是一样的
1. 先上代码: List<Person> list = new ArrayList<>(); Person p = new Person(); try { Class.for ...
- Qt QTextEdit根据行号移动光标
QTextEdit* p = new QTextEdit; QTextBlock block = p->document()->findBlockByNumber(nLineNum); p ...
- Java笔记 #04# 类的初始化顺序补充
参考java中的类的初始化顺序详解 package org.sample; class Bread { Bread() { System.out.println("Bread()" ...
- Docker学习笔记之在 Windows 和 Mac 中使用 Docker
0x00 概述 对于开发来说,Windows 和 macOS 是更为常见和常用的系统,所以也很有必要了解在 Windows 和 macOS 中使用 Docker 的方法.很幸运的是,Docker 的官 ...
- centos 6.5 gdb 7.10安装make[5]: *** [install-bfdincludeHEADERS] Error 1解决
make[5]: *** [install-bfdincludeHEADERS] Error 1make[5]: Leaving directory `/usr/local/gdb-7.10/bfd' ...
- Mac下Homebrew的安装与使用
Homebrew简介,安装与使用 简介 Homebrew 官方网站 Homebrew是一个包管理器,用于安装Apple没有预装但你需要的UNIX工具.(比如著名的wget). Homebrew会将软件 ...
- 20145212 罗天晨 《网络对抗》Exp3 Advanced 恶意代码伪装技术实践
恶意代码伪装技术实践 木马化正常软件. 啊哈--原本以为很复杂--然后我看了一下蔡野同学的博客,发现原理竟然如此简单-- 对原先生成病毒的代码稍作修改: 于是--把生成的后门软件改成骗人的名字:这里改 ...
- 使用msi自动安装系统
在实际生活中, 还是要尽量使用 自动化 脚本 等来处理/执行问题, 那样更快更省力省时间 要多使用 网络工具, 网络工具在 管理/ 使用网络的过程 中还是很有用的. 要有这种 "多使用网络工 ...
- BFS广度优先 vs DFS深度优先 for Binary Tree
https://www.geeksforgeeks.org/bfs-vs-dfs-binary-tree/ What are BFS and DFS for Binary Tree? A Tree i ...