题解:状态压缩之后,暴力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. 在多台手机上批量安装apk

    1.手机要打开adb调试 2.该程序可以实现台android手机的多个apk批量安装 1.getSeriaoNum.py模块,该模块获取已连接手机的序列号 import os import threa ...

  2. SVN needs-lock 设置强制只读属性【转】

    https://www.jianshu.com/p/5942ab19620b 设置后向svn服务器添加文件时,会自动带上svn:needs-lock属性,默认是只读的要签出才能修改,以避免不必要的编辑 ...

  3. SO_REUSEADDR的分析

    今天协议个socket程序时碰到了这个问题,选自博客http://www.cppblog.com/ace/archive/2006/04/29/6446.html 敲完代码,等下看它.

  4. 30个Python物联网小实验3:使用按钮开灯关灯

    使用按钮开灯关灯 接线图非常简单,LED接GPIO17号口,按钮接GPIO2号口,负极接GND地线. 代码也非常简单: from gpiozero import LED, Button from si ...

  5. 剑指Offer的学习笔记(C#篇)-- 矩形覆盖

    题目描述 我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形.请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法? 一 . 解题思路 这个貌似就是普通的跳台阶问题. 二 . 代 ...

  6. IOS UILabel的一些使用小技巧

    1. 你在iOS6的需要NSLineBreakByWordWrapping 为了您的代码试试这个: NSString *string = @"bla"; CGSize s = [s ...

  7. 微服务监控神器Prometheus的安装部署

    本文涉及:如何在k8s下搭建Prometheus+grafana的监控环境 基本概念 Prometheus提供了容器和云原生领域数据搜集.存储.处理.可视化和告警一套完整的解决方案,最初时是由Soun ...

  8. 黑马旅游网 url-pattern不加斜杠报错 java.util.concurrent.ExecutioException: org.apache.catalina.LifecycleException

  9. Vuex有哪些作用

    1.Vuex实现路由数据通讯 点击跳转路由的时候,把写入vuex,跳转后取出vuex

  10. 2017 ACM/ICPC Asia Regional Shenyang Online cable cable cable

    Problem Description Connecting the display screen and signal sources which produce different color s ...