题解:状态压缩之后,暴力dfs,如果有一个选择,能让对手必败,那么就是必胜态,能转移到的状态都是对手的必胜态,或者无法转移,就是必败态。

总算是过了,TLE是因为状态没判重。

#include<cstdio>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
typedef long long ll;
//#define local const int maxn = ; char str[maxn];
int n,m;
struct Node
{
char h,r;
}; Node P[][];
bool G[][][];
bool vis[<<]; bool dfs(int p,int u,int sta)
{
for(int v = ,sz = p?m:n; v < sz; v++) if(G[p][u][v]&&!((sta>>(v+p*))&)) {
int newsta = sta|(<<(v+p*));
if(vis[newsta]) continue;
vis[newsta] = ;
if(!dfs(p^,v,newsta)) return true;
vis[newsta] = ;
}
return false;
}
int main()
{
#ifdef local
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif // local
int T;
scanf("%d",&T);
for(int k = ; k <= T; k++){
scanf("%d",&n); getchar();
for(int i = ; i < n; i++){
gets(str);
P[][i].h = *str;
P[][i].r = str[strlen(str)-];
}
scanf("%d",&m); getchar();
for(int i = ; i < m; i++){
gets(str);
P[][i].h = *str;
P[][i].r = str[strlen(str)-];
} memset(G,,sizeof(G));
for(int i = ; i < n; i++){
for(int j = ; j < m; j++){
if(P[][i].r == P[][j].h) {
G[][i][j] = ;
}
if(P[][j].r == P[][i].h) {
G[][j][i] = ;
}
}
}
memset(vis,,sizeof(vis));
bool p1Win = false;
for(int i = ; i < n; i++){
if(!dfs(,i,<<i)) { p1Win = true; break; };
}
printf("Game %d: player%d\n",k,p1Win?:); }
return ;
}

codeforce Gym 100500A Poetry Challenge(博弈,暴搜)的更多相关文章

  1. CodeForces Gym 100500A A. Poetry Challenge DFS

    Problem A. Poetry Challenge Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...

  2. 【BZOJ-3033】太鼓达人 欧拉图 + 暴搜

    3033: 太鼓达人 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 204  Solved: 154[Submit][Status][Discuss] ...

  3. c++20701除法(刘汝佳1、2册第七章,暴搜解决)

    20701除法 难度级别: B: 编程语言:不限:运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述     输入正整数n,按从小到大的顺序输出所有 ...

  4. Codeforces Round #238 (Div. 2) D. Toy Sum 暴搜

    题目链接: 题目 D. Toy Sum time limit per test:1 second memory limit per test:256 megabytes 问题描述 Little Chr ...

  5. poj 3080 Blue Jeans(水题 暴搜)

    题目:http://poj.org/problem?id=3080 水题,暴搜 #include <iostream> #include<cstdio> #include< ...

  6. Sicily1317-Sudoku-位运算暴搜

    最终代码地址:https://github.com/laiy/Datastructure-Algorithm/blob/master/sicily/1317.c 这题博主刷了1天,不是为了做出来,AC ...

  7. codeforces 339C Xenia and Weights(dp或暴搜)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Xenia and Weights Xenia has a set of weig ...

  8. Usaco 2.3 Zero Sums(回溯DFS)--暴搜

    Zero SumConsider the sequence of digits from 1 through N (where N=9) in increasing order: 1 2 3 ... ...

  9. HDU4403(暴搜)

    A very hard Aoshu problem Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

随机推荐

  1. 2-1 本章作业&2-2 开发系统与工具选择

    2-1 2-2 推荐使用Android Studio开发Flutter

  2. (I/O完成端口中的)995错误

    在windows下,可能会出现995的错误,msdn对该错误的解释为: The I/O operation has been aborted because of either a thread ex ...

  3. ACM-ICPC2018焦作网络赛 Transport Ship(二进制背包+方案数)

    Transport Ship 25.78% 1000ms 65536K   There are NN different kinds of transport ships on the port. T ...

  4. HDU 2112 HDU Today Dij+map转化

    HDU Today 经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强.这时候,XHD夫妇也退居了二线,并 ...

  5. ASP.NET自定义控件组件开发

    ASP.NET的开发都是事件驱动的,现在我们就来为控件添加事件.在事件之前 对委托事件要要熟悉. 其实定义事件的步骤很简单: 1.声明一个委托. 2.定义一个携带事件信息的类. 3.定义事件 4.定义 ...

  6. Unite Europe案例项目《影子战术》层级优化经验分享

    http://forum.china.unity3d.com/thread-25087-1-9.html 在Unite Europe 2017的Keynote主题演讲中,我们为大家分享了将主机游戏&l ...

  7. SpringMVC 控制器写多个方法(非注解方式)

    Controller类有两种方法 1,implements Controller(实现Controller接口) 2,extends MultiActionController(继承 MultiAct ...

  8. SpringBoot(1)—启动原理之SpringApplication对象的创建

    创建SpringApplication对象 SpringBoot版本为 2.1.1.RELEASE @SpringBootApplication public class SpringbootDemo ...

  9. 小白入门AI教程:教你快速搭建大数据平台『Hadoop+Spark』

    Apache Spark 简介 Apache Spark 是专为大规模数据处理而设计的快速通用的计算引擎.Spark是UC Berkeley AMP lab (加州大学伯克利分校的AMP实验室)所开源 ...

  10. [Java]String、 StringBuffer、StringBuilder的区别

    一.异同点: 1) 都是 final 类, 都不允许被继承; 2) String 长度是不可变的, StringBuffer.StringBuilder 长度是可变的; 3) StringBuffer ...