题目链接:传送门

题目大意:

  在一个有N个点的拓扑图上(拓扑图以邻接表的形式输入),放M个棋子(棋子与棋子之间无关,可以重合)。

  两人轮流移动棋子,每次只能移动一个棋子经过一条边。

  问先手是否必胜。

思路:

  因为图是确定的,而且是拓扑图,直接沿着边跑记忆化dfs求每个点的SG值就可以了。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set> using namespace std;
const int MAX_N = ; int N, M;
int Edge[MAX_N][MAX_N];
int SG[MAX_N]; int dfs(int u)
{
if (SG[u] >= )
return SG[u];
bool vis[MAX_N];
memset(vis, false, sizeof vis);
for (int i = ; i <= Edge[u][]; i++) {
int v = Edge[u][i];
int x = dfs(v);
vis[x] = true;
}
int g = ;
while (vis[g])
g++;
return SG[u] = g;
} int main()
{
while (~scanf("%d", &N)) {
for (int i = ; i < N; i++) {
SG[i] = -;
scanf("%d", &Edge[i][]);
for (int j = ; j <= Edge[i][]; j++) {
scanf("%d", &Edge[i][j]);
}
}
for (int i = ; i < N; i++)
dfs(i); while (~scanf("%d", &M)) {
if (M == )
break;
int ans = ;
while (M--) {
int cur;
scanf("%d", &cur);
ans ^= SG[cur];
}
if (ans)
puts("WIN");
else
puts("LOSE");
}
}
return ;
}

POJ2425 A Chess Game(SG函数+记忆化深搜)的更多相关文章

  1. poj 3249 Test for Job (记忆化深搜)

    http://poj.org/problem?id=3249 Test for Job Time Limit: 5000MS   Memory Limit: 65536K Total Submissi ...

  2. POJ 2311 Cutting Game(Nim博弈-sg函数/记忆化搜索)

    Cutting Game 题意: 有一张被分成 w*h 的格子的长方形纸张,两人轮流沿着格子的边界水平或垂直切割,将纸张分割成两部分.切割了n次之后就得到了n+1张纸,每次都可以选择切得的某一张纸再进 ...

  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(SG函数+状态压缩)

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

  5. 2016多校联合训练1 B题Chess (博弈论 SG函数)

    题目大意:一个n(n<=1000)行,20列的棋盘上有一些棋子,两个人下棋,每回合可以把任意一个棋子向右移动到这一行的离这个棋子最近的空格上(注意这里不一定是移动最后一个棋子),不能移动到棋盘外 ...

  6. P4363 [九省联考2018]一双木棋chess(对抗搜索+记忆化搜索)

    传送门 这对抗搜索是个啥玩意儿…… 首先可以发现每一行的棋子数都不小于下一行,且局面可由每一行的棋子数唯一表示,那么用一个m+1进制数来表示当前局面,用longlong存,开map记忆化搜索 然后时间 ...

  7. POJ-3635 Full Tank? (记忆化广搜)

    Description After going through the receipts from your car trip through Europe this summer, you real ...

  8. HDU 5724 Chess (sg函数)

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

  9. POJ 2425 A Chess Game 博弈论 sg函数

    http://poj.org/problem?id=2425 典型的sg函数,建图搜sg函数预处理之后直接求每次游戏的异或和.仍然是因为看不懂题目卡了好久. 这道题大概有两个坑, 1.是搜索的时候vi ...

随机推荐

  1. Springboot+Mybatis批量导入多条数据

    在Mapper.xml最下面填写 <!-- 批量插入生成的兑换码 --> <insert id ="insertCodeBatch" parameterType= ...

  2. 回声TCP服务器端/客户端

    一.TCP服务端 1.TCP服务端的默认函数调用顺序 socket()创建套接字 bind()分配套接字地址 listen()等待请求连接状态 accept()允许连接 read()/write()数 ...

  3. ubuntu中更新.netcore到2.1版本

    如果需要安装新版本到dotnetcore,需要先卸载旧版本(https://github.com/dotnet/core/blob/master/release-notes/download-arch ...

  4. VIM编辑配置文件基本操作

    vim  /etc/apt/sources.list 按insert键进入编辑状态 编辑完成以后按ESC退出编辑状态 输入 ":"进入命令状态,常用命令: 1.W:write ,写 ...

  5. laravel的日志服务

    日志服务使用: $app=app(); $log=$app->make('log'); $log->info('post_index',['data'=>'this is post ...

  6. body中的onload()函数和jQuery中的document.ready()有什么区别?

    1.我们可以在页面中使用多个document.ready(),但只能使用一次onload(). 2.document.ready()函数在页面DOM元素加载完以后就会被调用,而onload()函数则要 ...

  7. 一. Python基础(1)--语法

    一. Python基础(1)--语法 1. 应用程序 1.1 什么是计算机(Computer)? 组成 ①运算器 arithmetic unit; ※ Arithmetic unit and cont ...

  8. 愛與痛的邊緣--IPA--粤语

    谭咏麟和王菲的版本各有味道.

  9. Edit Distance II

    Given two strings S and T, determine if they are both one edit distance apart. Example Given s = &qu ...

  10. Cracking The Coding Interview 5.6

    //Write a program to swap odd and even bits in an integer with as few instructions as possible (e.g. ...