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 ...
随机推荐
- Linux初始root密码设置
刚安装好的Linux系统是没有设置root用户密码的,下边介绍如何设置root用户的密码 第一步:sudo passwd 第二步:输入密码 第三步:确认密码 这样三个步骤过后root用户的密码就设置好 ...
- java 子类的实例化和代码块初始化过程
1,子类的实例化 1,子父类中的构造函数的特点. 在子类构造对象时,发现,访问子类构造函数时,父类也运行了. 为什么呢? 原因是:在子类的构造函数中第一行有一个默认的隐式语句. super(); 子类 ...
- Python基于比较的排序
排序是算法学习中最基本的问题. 1.平均时间复杂度均为O(N2)的排序 1.1 插入排序 插入排序对少量元素的排序非常有效.工作机制就像打牌一样,为了将牌插入到已排好序的牌中,需要将牌与手中的牌从右向 ...
- hdu 1695 GCD 莫比乌斯反演入门
GCD 题意:输入5个数a,b,c,d,k;(a = c = 1, 0 < b,d,k <= 100000);问有多少对a <= p <= b, c <= q <= ...
- NGUI系列教程一
NGUI是Unity的一个插件,使用它来制作你的游戏UI必定将事半功倍.为什么这么说呢?首先我们说说GUI与NGUI的区别,GUI是Unity自带的绘制界面工具,它的成像原理是基于表层的,所以执行效率 ...
- 25个App免费资源网站
不少非常优秀的设计师已经在网络分享了很多出色的图标.界面 PSD 文件,再加上其他一些相关资源,设计 iOS 应用更加方便了. 模板 & PSDs Icon Template Michael ...
- Automotive Security的一些资料和心得(8):Hardware Security Module (HSM)
1. Introduction - 保护软件的安全性措施,作为值得信赖的安全锚,- 安全地生成,存储和处理安全性关键材料屏蔽任何潜在的恶意软件,?- 通过运用有效的限制硬件篡改攻击的可能性篡改保护措施 ...
- C#如何控制方法的执行时间,超时则强制退出方法执行
转自:http://outofmemory.cn/code-snippet/1762/C-how-control-method-zhixingshijian-chaoshi-ze-force-quit ...
- 《ASP.NET 本质论》HttpApplication的处理管道 ,HttpMoudle,HttpHandler
http://blog.csdn.net/sky1069/article/details/6659667 handler :http://blog.csdn.net/keymo_/article/de ...
- c++ 输入一行字符串
]; //cin>>str1; 方式1 不能统计(录入)空格后的字符 cin.); //方式2 能统计空格后输入的字符 按回车键输入结束 get()会将换行符保存在序列里 //gets(s ...