题目链接:传送门

题目大意:

  在一个有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. Spring @Scheduled @Async联合实现调度任务(2017.11.28更新)

    定时任务之前一直用的是quartz之类,但是注意到Spring中其实也提供了一种简单的调度注释@Scheduled,也就想尝一下鲜.. 代码示意如下: @Component @EnableSchedu ...

  2. Object转Integer,String

    object先转为字符串,然后通过int 的封装类(Integer)的pasreInt()方法转为int 例如: Object  ob = 123; Integer.parseInt(String.v ...

  3. LeetCode刷题 Flood Fill 洪水填充问题

    An  image is represented by a 2-D array of integers,each integers,each integer respresenting the sta ...

  4. hdu3518

    题解: 后缀数组 枚举长度为k(1<=k<=len/2)的满足要求的子串个数 代码: #include<cstdio> #include<cmath> #inclu ...

  5. oo作业总结(四)

    测试与正确性论证 测试是通过构造一系列测试数据,通过对比程序的实际运行结果和预期输出结果来判断程序是否有bug的一种手段.同时,在测试的时候是默认看不到程序的具体实现的,即进行黑盒测试,例如每次OO作 ...

  6. 查找xml中的接口名及涉及表名并输出

    #! /usr/bin/env python3 # -*- coding:utf-8 -*- import xml.dom.minidom  #该模块被用来处理xml文件 import re #正则表 ...

  7. jstree使用新的

    1.首先准备jstree树的dom元素 <p id="flowList_ul" class="flowList_ul"></p> 2.初 ...

  8. core net 实现post 跟get

    using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using Syst ...

  9. 打开和写入excel文件

    一.使用win32读取excel内容 # -*- coding: utf-8 -*- from win32com import client as wc def open_excel(): excel ...

  10. pragma comment的使用 pragma预处理指令详解

    pragma comment的使用 pragma预处理指令详解   #pragma comment( comment-type [,"commentstring"] ) 该宏放置一 ...