1.不会超过500个不同的串……

2.样例没给has到has是怎么样的,实测是true。

3.记忆化别剪错枝就好,嘤嘤嘤……

const int maxn = 505 + 5;
int n, m, tot;
string s, op, t;
bool can[maxn][maxn][2], used[maxn][2];
map<string, int> id; void GetId(string s) {
if (!id[s]) id[s] = ++tot;
} void dfs(int f, int cur, int op) {
if (used[cur][op]) return;
used[cur][op] = can[f][cur][op] = 1; rep(i, 1, tot) {
if (can[cur][i][0]) dfs(f, i, op);
if (can[cur][i][1]) dfs(f, i, 1);
}
} int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> m;
rep(i, 1, n) {
cin >> s >> op >> t;
GetId(s), GetId(t);
can[id[s]][id[t]][op[0] != 'i'] = 1;
} rep(i, 1, tot) {
init(used, 0);
dfs(i, i, 0);
} rep(i, 1, m) {
cin >> s >> op >> t;
cout << "Query " << i << ": ";
cout << (can[id[s]][id[t]][op[0] != 'i'] ? "true" : "false") << endl;
} return 0;
}

GYM 101673E(暴搜预处理)的更多相关文章

  1. HDU 4284 Travel (Folyd预处理+dfs暴搜)

    题意:给你一些N个点,M条边,走每条边要花费金钱,然后给出其中必须访问的点,在这些点可以打工,但是需要先拿到证书,只可以打一次,也可以选择不打工之直接经过它.一个人从1号点出发,给出初始金钱,问你能不 ...

  2. suoi62 网友跳 (暴搜+dp)

    传送门 sbw太神啦orz 首先N<=20可以直接暴搜 然后玄学剪枝可以过18个点 那么N<=40的时候,就把它拆成两半分别暴搜,再用dp拼起来 对于前半段,设f[i][j]是开始高度为i ...

  3. 紫书 习题 10-25 UVa 1575 (有重复元素的全排列+暴搜)

    我一开始以为有什么很牛逼的方法来做,然后一直没有思路 后来看了https://blog.csdn.net/zju2016/article/details/78562932的博客 竟然是暴搜?????? ...

  4. [bzoj]1053反质数<暴搜>

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1053 感想:这道题拿到以后还是想去知道一个数的约数个数要怎么求,去网上搜了公式,但是还是没有思 ...

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

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

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

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

  7. 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 ...

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

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

  9. Sicily1317-Sudoku-位运算暴搜

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

随机推荐

  1. leetcode 748. Shortest Completing Word

    Find the minimum length word from a given dictionary words, which has all the letters from the strin ...

  2. LightOJ1236 —— 唯一分解定理 + 最小公倍数

    题目链接:https://vjudge.net/problem/LightOJ-1236 1236 - Pairs Forming LCM    PDF (English) Statistics Fo ...

  3. CodeForces - 86D D. Powerful array —— 莫队算法

    题目链接:http://codeforces.com/problemset/problem/86/D D. Powerful array time limit per test 5 seconds m ...

  4. 驻守深寒:寻找那些有效地关键K线

    K线是组成投机市场的基本符号,也是技术分析的基本工具.可是面对浩如烟海的杂乱K线,特别是市场盘整时,经常使人们的判断发生混乱.支撑之下有支撑,阻力之上有阻力. 前人总结了大量的K线组合和由K线组成的技 ...

  5. Eclipse 插件使用

    1. AmaterasUML:UML 类图(class diagram) 注意这里是先编写好代码,通过插件根据代码逻辑关系生成类图: 安装AmaterasUML前,需要先安装 GEF,采用 eclip ...

  6. SDOI2017 Round1 Day2 题解

    T2好厉害啊……AK不了啦……不过要是SCOI考这套题就好了240保底. BZOJ4819 新生舞会 模板题,分数规划+二分图最大权匹配. 费用流跑得过,可以不用KM. UPD:分数规划用迭代跑得飞快 ...

  7. 「DP」区间dp

    区间dp? 状态设计为描述一段区间的dp. eg:f[i][j]表示从 i 到 j 这个区间上的最优值.

  8. Subset Sums

    链接 分析:dp[i][j]表示前i个数能够组成j的对数,可得dp[i][j]=dp[i-1][j]+dp[i-1][j-i],所以最后dp[n][sum/2]既是所求 /* PROB:subset ...

  9. SP8093 JZPGYZ - Sevenk Love Oimaster

    传送门 广义后缀自动机-- 其实也不是很难理解,就是每次SAM插入一个串之后,插入新的串的时候,要把last重新调到1的位置,共用一些节点. 这个题我们首先要预处理出来每个状态被多少个串共用.挺暴力的 ...

  10. Ubuntu12.04下安装VirtualBox

    目录: 安装虚拟机VirtualBox 虚拟机VirtualBox安装win7全过程 虚拟机共享文件夹.U盘 一.安装虚拟机VirtualBox VirtualBox下载地址:https://www. ...