题解:状态压缩之后,暴力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. 自己在项目中写的一个Jquery插件和Jquery tab 功能

    后台查询结果 PDFSearchResult实体类: [DataContract(Name = "PDFSearchResult")] public class PDFSearch ...

  2. 教你如何暴力破解-telnet ftp ssh mysql mssql vnc 等

    大家应该都知道暴力破解的原理,但却不知道遇见telnet和ftp等服务和数据库如何破解,今天小R就教大家如何利用一个工具就能对其破解. 今天要给大家介绍的工具是:hydra(中文名:九头蛇) 这个名听 ...

  3. [nyoj]会场安排问题-贪心

    会场安排问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工 ...

  4. BitMap的原理以及运用

    位图(Bitmap),即位(Bit)的集合,是一种数据结构,可用于记录大量的0-1状态,在很多地方都会用到,比如Linux内核(如inode,磁盘块).Bloom Filter算法等,其优势是可以在一 ...

  5. LDAP理论知识

    整理改编自: https://www.cnblogs.com/yjd_hycf_space/p/7994597.html http://blog.51cto.com/407711169/1439623 ...

  6. day3字符串操作作业详解

    1.day3题目 1.有变量name = "aleX leNb" 完成如下操作: 1) 移除 name 变量对应的值两边的空格,并输出处理结果 2) 移除name变量左边的&quo ...

  7. VxWorks实验六 基于优先级的抢占式调度及实验的源程序和实验步骤

    基于优先级的抢占式调度及实验的源程序和实验步骤 1 实验目的    1.学习并验证基于优先级的抢占式调度2 实验内容    在实验一建立的 project 中,创建3 个任务,对这三个任务使用基于优先 ...

  8. [Android基础]Android四大组件之Activity总结

    1.Activity简介 Activity是Android一个非常重要的用户接口(四大组件之一),是可见的,主要是用户和应用程序之间进行交互的接口.在每个Activity中都可以放很多控件,所以也可以 ...

  9. 题解 poj1845 Sumdiv (数论) (分治)

    传送门 大意:求A^B的所有因子之和,并对其取模 9901再输出 (这题又调了半天,把n和项数弄混了QAQ) 根据算数基本定理:A=(p1^k1)*(p2^k2)*(p3^k3)*...*(pn^kn ...

  10. GYM 101933K(二项式反演、排列组合)

    方法一 设\(f_i\)为最多使用\(i\)种颜色的涂色方案,\(g_i\)为恰好只使用\(i\)种颜色的涂色方案.可知此题答案为\(g_k\). 根据排列组合的知识不难得到\(f_k = \sum_ ...