http://lightoj.com/volume_showproblem.php?problem=1051

对于每个位置,设dfs(cur, one, two)表示前i个字母,拥有辅音字母one个,元音字母two个的情况。

目标是使得cur移动到结尾,这样就是能产生good串。然后超时

记忆化搜索。

比如前面的字符串是

JFLKAJS??FHJADJFA?

我不管前面的问号变了什么,也不管前面的东西是什么情况,假如,假如我的最后一个问号是变了元音,那么它下一个状态肯定

就是dfs(cur + 1, 0, two + 1),也就是辅音变成了0个。这样会使得很多状态重复了。所以记录一下就好。

JFLKAJS??FHJADJFA   ?   JFIJIJASLH??SDUAFHK??,也就是考虑现在空格分开的那个问号,假如我是把它变了元音,

它的连续的元音是2个,辅音是0个,这是固定了的状态了,如果搜索过的话,后面的已经不用枚举了。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
bool is[];
int dp[ + ][ + ][ + ];
int DFN, lenstr;
char str[];
bool good, bad;
void dfs(int cur, int one, int two) {
if (dp[cur][one][two] == DFN) return;
dp[cur][one][two] = DFN;
if (bad && good) return;
if (one == || two == ) {
bad = true;
return;
}
if (cur == lenstr + ) {
good = true;
return;
}
if (str[cur] == '?') {
dfs(cur + , one + , );
dfs(cur + , , two + );
} else {
if (is[str[cur]]) {
dfs(cur + , , two + );
} else dfs(cur + , one + , );
}
}
void work() {
scanf("%s", str + );
lenstr = strlen(str + );
++DFN;
good = false, bad = false;
dfs(, , );
static int f = ;
if (good && bad) {
printf("Case %d: MIXED\n", ++f);
} else if (bad) {
printf("Case %d: BAD\n", ++f);
} else {
printf("Case %d: GOOD\n", ++f);
}
}
int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
is['A'] = is['E'] = is['I'] = is['O'] = is['U'] = true;
int t;
scanf("%d", &t);
while (t--) work();
return ;
}

1051 - Good or Bad DFS 记忆化搜索的更多相关文章

  1. 不要62 hdu 2089 dfs记忆化搜索

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2089 题意: 给你两个数作为一个闭区间的端点,求出该区间中不包含数字4和62的数的个数 思路: 数位dp中 ...

  2. dfs+记忆化搜索,求任意两点之间的最长路径

    C.Coolest Ski Route 题意:n个点,m条边组成的有向图,求任意两点之间的最长路径 dfs记忆化搜索 #include<iostream> #include<stri ...

  3. hdu 1078 FatMouse and Cheese (dfs+记忆化搜索)

    pid=1078">FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/ ...

  4. hdu 1078(dfs记忆化搜索)

    题意:容易理解... 思路:我开始是用dfs剪枝做的,968ms险过的,后来在网上学习了记忆化搜索=深搜形式+dp思想,时间复杂度大大降低,我个人理解,就是从某一个点出发,前面的点是由后面的点求出的, ...

  5. UVA 10400 Game Show Math (dfs + 记忆化搜索)

    Problem H Game Show Math Input: standard input Output: standard output Time Limit: 15 seconds A game ...

  6. 8636 跳格子(dfs+记忆化搜索)

    8636 跳格子 该题有题解 时间限制:2457MS  内存限制:1000K提交次数:139 通过次数:46 题型: 编程题   语言: G++;GCC Description 地上有一个n*m 的数 ...

  7. poj1088-滑雪 【dfs 记忆化搜索】

    http://poj.org/problem?id=1088 滑雪 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 79806 ...

  8. DFS——>记忆化搜索——>动态规划

    以洛谷P1802  5倍经验日 为例 https://www.luogu.org/problem/show?pid=1802 题目背景 现在乐斗有活动了!每打一个人可以获得5倍经验!absi2011却 ...

  9. POJ 1191 棋盘分割 【DFS记忆化搜索经典】

    题目传送门:http://poj.org/problem?id=1191 棋盘分割 Time Limit: 1000MS   Memory Limit: 10000K Total Submission ...

随机推荐

  1. web 前端冷知识

    前端已经被玩儿坏了!像console.log()可以向控制台输出图片等炫酷的玩意已经不是什么新闻了,像用||操作符给变量赋默认值也是人尽皆知的旧闻了,今天看到Quora上一个帖子,瞬间又GET了好多前 ...

  2. hihoCoder 1586 Minimum 【线段树】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1586 : Minimum 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You are given a list of integers a0, a1, …, a2 ...

  3. spring-jar包详解整理(大合集)

    转:https://blog.csdn.net/weisong530624687/article/details/50888094 spring.jar 是包含有完整发布模块的单个jar 包.但是不包 ...

  4. Eclipse 创建新的workspace

    工具:eclipse  版本:4.5.1 1.配置jdk(java-Compiler).maven(Mven-User Settings) 2.从svn拉取项目,创建.project(修改其项目名称) ...

  5. 汉字与区位码互转(天天使用Delphi的String存储的是内码,Windows记事本存储的文件也是内码),几个常见汉字的各种编码,utf8与unicode的编码在线查询,附有读书笔记 good

    汉=BABA(内码)=-A0A0=2626(区位码)字=D7D6(内码)=-A0A0=5554(区位码) 各种编码查询表:http://bm.kdd.cc/ 汉(记住它,以后碰到内存里的数值,就会有敏 ...

  6. 学习js所必须要知道的一些

    1.document.write(""); 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document->html->(head,body) 4. ...

  7. HashSe、LinkedHashSet、TreeSet(java基础知识十七)

    1.HashSet存储字符串并遍历 * 特点:无序.无索引.无重复 HashSet存储字符串并遍历 HashSet<String> hs = new HashSet<>(); ...

  8. ubuntu docker的安装和使用

    Docker CE for Ubuntu Docker CE for Ubuntu is the best way to install the Docker platform on Ubuntu L ...

  9. POJ2689:Prime Distance(大数区间素数筛)

    The branch of mathematics called number theory is about properties of numbers. One of the areas that ...

  10. sscanf非常的重要

    刚进研究生阶段,发现曾经学习的c语言真的好少好少,很少能够看见scanf printf等..... 以后实验的80%以上都是在linux下面 老师让我看看关于一个日志会聚的一个项目模块 发现基本上都是 ...