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. async函数学习笔记

    含义 async函数是什么?一句话,它就是Generator函数的语法糖. const fs = require('fs') const readFile = function(fileName){ ...

  2. Codeforces Round #258 (Div. 2) D. Count Good Substrings —— 组合数学

    题目链接:http://codeforces.com/problemset/problem/451/D D. Count Good Substrings time limit per test 2 s ...

  3. ping请求超时的解决方法

    我们有时需要进行远程或者共享对方数据库的时候,会ping一下对方电脑,时候能够ping通,时候能够进行数据的传输.有时会出现ping请求超时,那么遇到这个问题该怎么解决? 我们首要解决的是看他自己是否 ...

  4. 使用eclipse的SVN连接码云

    码云配置: 码云的项目上,启用SVN访问 eclipse的配置,不配置这个会报错

  5. haproxy参数解析

    HAProxy工作于隧道模式,其仅检查每一个连接的第一个请求, 1. option abortonclose #当服务器负载过高时,将自动关闭队列中处理时间较长的连接请求 2. option http ...

  6. EnumDescription

    using System; using System.Reflection; using System.Collections; using System.Collections.Generic; n ...

  7. hadoop各组件安装(非专业人士,不定期更新)

    压缩包下载http://www.cnblogs.com/bfmq/p/6027202.html 1.zookeepermkdir /usr/local/hadooptar zxf /root/zook ...

  8. Lecture0 -- Introduction&&Linear Regression with One Variable

    Introduction What is machine learning? Tom Mitchell provides a more modern definition: "A compu ...

  9. vs缩进多行,vs2013测试可用

    vs缩进多行,vs2013测试可用 选中要缩进的行,然后点击tab会直接在选中行增大缩进 快捷键 功能 描述 tab 增大缩进 选中要缩进的行,可多行 shift + table 减小缩进 选中要缩进 ...

  10. 查看电脑MAC地址

    MAC地址也叫物理地址 1.运行 cmd 输入ipconfig或ipconfig/all