HDU 5724:Chess(博弈 + 状压)
http://acm.hdu.edu.cn/showproblem.php?pid=5724
Chess
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.
题意:两个人下棋,棋盘有n行20列,每一行有m个棋子分别位于p,棋子只能往右走,如果有相邻的棋子,可以跳过这个棋子,当不能动的时候就输了,问先手能不能赢。
思路:因为只有20列,可以状态压缩,打表枚举一行的所有状态,然后所有行状态的sg值异或起来就是答案。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 21 int sg[<<N];
bool vis[]; int get_sg(int now)
{
memset(vis, , sizeof(vis));
int i;
//终止点为第20列,在这里的第20列为i = 0,因为i = 0的时候为必败点P
//从第一列开始枚举,找到属于该状态的列,并且在该列下枚举,找到不属于该状态的列
for(i = ; i >= ; i--) {
if(now & ( << i)) {
int tmp = now;
for(int j = i - ; j >= ; j--) {
if(!(now & ( << j))) {
//这里异或的结果相当于第20-i列的棋子走到第20-j列的状态
tmp ^= ( ( << i) ^ ( << j) );
vis[sg[tmp]] = ;
break;
}
}
}
}
for(i = ; i <= ; i++)
if(!vis[i]) {
sg[now] = i;
break;
}
} int main()
{
sg[] = ;
for(int i = ; i <= ( << ); i++)
get_sg(i);
//打表枚举所有状态
int t;
scanf("%d", &t);
while(t--) {
int n, ans = , m, x, y;
scanf("%d", &n);
for(int i = ; i <= n; i++) {
scanf("%d", &m);
x = ;
for(int j = ; j <= m; j++) {
scanf("%d", &y);
x |= ( << ( - y));
//x = 所有有棋子的列加起来的状态
}
ans ^= sg[x];
//最后的结果是所有行异或
// printf("ANS : %d\n", ans);
}
if(ans == ) puts("NO");
else puts("YES");
}
return ;
}
HDU 5724:Chess(博弈 + 状压)的更多相关文章
- hdu 5724 Chess 博弈sg+状态压缩
Chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Problem De ...
- hdu 5724 Chess 博弈
题目链接 一个n行20列的棋盘. 每一行有若干个棋子. 两人轮流操作, 每人每次可以将一个棋子向右移动一个位置, 如果它右边有一个棋子, 就跳过这个棋子, 如果有若干个棋子, 就将这若干个都跳过. 但 ...
- HDU 5724 Chess(国际象棋)
HDU 5724 Chess(国际象棋) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Oth ...
- hdu 3247 AC自动+状压dp+bfs处理
Resource Archiver Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 100000/100000 K (Java/Ot ...
- hdu 2825 aC自动机+状压dp
Wireless Password Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu 4778 Gems Fight! 状压dp
转自wdd :http://blog.csdn.net/u010535824/article/details/38540835 题目链接:hdu 4778 状压DP 用DP[i]表示从i状态选到结束得 ...
- HDU 3605 Escape(状压+最大流)
Escape Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Sub ...
- HDU 5765 Bonds 巧妙状压暴力
题意:给一个20个点无向连通图,求每条边被多少个极小割集包括 分析:极小割集是边的集合,很显然可以知道,极小割集恰好吧原图分成两部分(这个如果不明白可以用反证法) 然后就是奉上官方题解:http:// ...
- HDU 5765 Bonds(状压DP)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5765 [题目大意] 给出一张图,求每条边在所有边割集中出现的次数. [题解] 利用状压DP,计算不 ...
随机推荐
- autorelease基本概念
// // main.m // 01-autorelease基本概念 // // Created by apple on 14-3-18. // Copyright (c) 2014年 app ...
- html 把左框的选中项添加到右框
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- iOS 瀑布流的Demo
/** * 瀑布流Demo的主要代码,若想看完整的代码请到下面链接去下载 * * 链接: https://pan.baidu.com/s/1slByAHB 密码: r3q6 */ #import &l ...
- spring消费RESTfull服务
使用RestTemplate做这件事非常简单 package hello; import org.slf4j.Logger; import org.slf4j.LoggerFactory; impor ...
- mysql慢查日志分析工具 percona-toolkit
备忘自: http://blog.csdn.net/seteor/article/details/24017913 1. 工具简介 pt-query-digest是用于分析mysql慢查询的一个工具, ...
- Tomcat系列之Java技术详解
一.概述 1.前言 在前面几篇博客中,我们和大家说了负载均衡器服务器.Web服务器.反向代理服务器.缓存服务器,从这篇博客开始我们和大家说说应用程序服务器,对于上述内容不了解的博友可以去参考一下我们前 ...
- 转:Python一些特殊用法(map、reduce、filter、lambda、列表推导式等)
Map函数: 原型:map(function, sequence),作用是将一个列表映射到另一个列表, 使用方法: def f(x): return x**2 l = range(1,10) map( ...
- 树形DP(01组合背包The Ghost Blows Light HDU4276)
题意:有n个房间,之间用n-1条道路连接,每个房间都有一个定时炸弹,在T时间后会一起爆炸,第i个房间有pi价值的珠宝,经过每条道路都需要花费一定的时间,一个人从1房间开始 ,从n房间出去,保证再不炸死 ...
- UISearchController的使用
- (void)addSearchController { _searchController = [[UISearchController alloc] initWithSearchResultsC ...
- [摘录]quarts:Quartz Quick Start Guide
(Primarily authored by Dafydd James) Welcome to the QuickStart guide for Quartz. As you read this gu ...