HDU 3427
DP:
According to the meaning of problems,if we check n to m, assume x and y are both solvable,then we only should:
(1). check xy;
(2). check AxA
(3). check AxAyA
if any one of the three is solvable , n to m is solvable
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN = 200;
char str[MAXN], dp[MAXN][MAXN];
bool dfs(int n, int m){
if(n > m) return true;
if(n == m) return false;
if(dp[n][m] == 1) return true;
if(dp[n][m] == -1) return false;
for(int i = n+1;i < m-1;i ++){
if(dfs(n, i) && dfs(i+1, m)){ //check xy;
dp[n][m] = 1;
return true;
}
}
if(str[n] == str[m]){
if(dfs(n+1, m-1)){ //check AxA
dp[n][m] = 1;
return true;;
}
for(int i = n+1;i < m;i ++){
if(str[i] != str[n]) continue;
if(dfs(n+1, i-1) && dfs(i+1, m-1)){ //check AxAyA
dp[n][m] = 1;
return true;
}
}
}
dp[n][m] = -1;
return false;
}
int main(){
memset(str, 0, sizeof(str));
freopen("in.c", "r", stdin);
while(~scanf("%s", str)){
memset(dp, 0, sizeof(dp));
int len = strlen(str);
if(dfs(0, len-1)) printf("solvable\n");
else printf("unsolvable\n");
}
return 0;
}
HDU 3427的更多相关文章
- (二分搜索 )Strange fuction -- HDU -- 2899
链接: http://acm.hdu.edu.cn/showproblem.php?pid=2899 Time Limit: 2000/1000 MS (Java/Others) Memory ...
- HDU 5641 King's Phone 模拟
King's Phone 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5641 Description In a military parade, ...
- HDU 4391 Paint The Wall(分块+延迟标记)
Paint The Wall Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
随机推荐
- Reactor模式(反应器模式)
Reactor这个词译成汉语还真没有什么合适的,很多地方叫反应器模式,但更多好像就直接叫reactor模式了,其实我觉着叫应答者模式更好理解一些.通过了解,这个模式更像一个侍卫,一直在等待你的召唤,或 ...
- windows 系统下,小数据量Oracle用户物理备份
环境:windows Server 2003 oracle 10g,系统间备份 目标系统创建共享文件,原系统挂载共享目录 写批处理脚本,用任务计划定时调用 Rem * 由于系统实时性要求不是很高,数据 ...
- jexus 启动失败 原因定位
现象: root@test:/usr/jexus/siteconf# /usr/jexus/jws restartRestarting ... Failure 定位步骤: 1.查看/usr/jexus ...
- TCO 2014 Round 1A
顺利搞出 A B 两题,然后压线晋级了,手速场. A 题 , 求排列最小的,肯定从后往前来做,维护一个最小的set,只是第一个字母要特判一下. 1: #line 5 "EllysSorti ...
- 个人作业-Homework1感想
我以前没有系统学习过C++和C#,编程能力比较差.这次个人作业对我来说是一个很大的挑战.由于布置作业的时间是开学的第一周,因为还没有从假期的状态中转换出来,这对我写作业又增加了一定的难度. 在开始写作 ...
- 野指针、NULL指针和void*
一.野指针 “野指针”不是NULL指针,是指向“垃圾”内存的指针. “野指针”的成因主要有三种: (1)指针变量没有被初始化.任何指针变量刚被创建时不会自动成为NULL指针,它的缺省值是随机的,它会乱 ...
- 【win8技巧】应用商店里面如何搜索应用app
win8应用商店搜索app软件的技巧 1.组合键 WIN+C 打开屏幕最右边磁条 2.点击搜索,输入你想搜的软件名称,里面会列出你已经安装的app或者你点击下面的应用商店选项,就可以搜索互联网上应用商 ...
- 如何用 Retrofit 2 在安卓上实现 HTTP 访问?
最近,笔者对安卓开发的兴趣愈发浓厚,而且不断尝试了许多传闻很棒的开发库 -- 大部分也真的很不错.于是打算写一个系列文章,介绍使用这些让人惊叹的库建立安卓示例应用的实践.这样,读者可以自行判断,这些库 ...
- Global中的事件执行顺序
The Global.asax file, sometimes called the ASP.NET application file, provides a way to respond to ap ...
- php smarty insert用法
insert用于模板中. 用法:{insert name="method_name"} 此时会寻找php文件中方法名为:insert_method_name的函数, 将其返回值作为 ...