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. 防sql注入 盲注等措施 ESAPI的使用

    SQL注入往往是在程序员编写包含用户输入的动态数据库查询时产生的,但其实防范SQL注入的方法非常简单.程序员只要a)不再写动态查询,或b)防止用户输入包含能够破坏查询逻辑的恶意SQL语句,就能够防范S ...

  2. ermissions on /usr/local/mongodb/conf/keyFile are too open

    ermissions on /usr/local/mongodb/conf/keyFile are too open > rs.initiate(cfg); { "ok" : ...

  3. JUNO eclipse Version: 4.2.0 添加svn插件

    1.下载最新的这个版本的SVN http://www.eclipse.org/subversive/latest-releases.php 实际的下载地址 http://www.eclipse.org ...

  4. 组合模式(遍历树,file基表示文件也表示文件夹)

    组合模式多个对象形成树形结构以表示“整体--部分”的结构层次.组合模式对单个对象(即叶子对象)和组合对象(即容器对象)的使用具有一致性. 组合模式又可以称为“合成模式“ 或 ”整体-部分模式”,属于对 ...

  5. Configuring Your EMS Server or EMS Console Server on Windows/Linux

    EMS Configuration Files RAD Studio provides the scripts to render the web-browser console, the EMS s ...

  6. Linux时间子系统之四:定时器的引擎:clock_event_device【转】

    本文转载自:http://blog.csdn.net/droidphone/article/details/8017604 版权声明:本文为博主原创文章,未经博主允许不得转载.   目录(?)[+] ...

  7. CodeChef:Little Elephant and Colored Coins

    类似墨墨的等式 设f[2][j][k]表示a[i].c是否和当前颜色相同,到当前枚举到的颜色为止,颜色数为j,对mnv取模为k的最小数 这是个无限循环背包,用spfa优化 #include<cs ...

  8. kentico检查当前授权用户,是否为admin角色

    https://docs.kentico.com/k11/custom-development/user-internals-and-api/checking-permissions-using-th ...

  9. 2款JS脚本判断手机浏览器跳转WAP手机网站

    随着移动设备的普及,企业的网络宣传已经不能局限在PC端,而需要同时在移动端有所建树.对于公司网站来说,以前都是做的PC端的,当然手机等移动端也可以访问,但是用户体验肯定不如完全适合的手机端来的方便.我 ...

  10. 目录操作(PHP)

    1.创建目录(文件夹)mkdir("./test");2.删除目录(文件夹)只能删除空的文件夹rmdir("./test");3.移动目录(文件夹)rename ...