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的更多相关文章

  1. (二分搜索 )Strange fuction -- HDU -- 2899

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=2899 Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  2. HDU 5641 King's Phone 模拟

    King's Phone 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5641 Description In a military parade, ...

  3. HDU 4391 Paint The Wall(分块+延迟标记)

    Paint The Wall Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  4. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  5. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  6. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  7. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  8. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  9. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

随机推荐

  1. CentOS下Apache+SVN+LDAP的安装与配置

    上班接近4个月了,在公司做配置管理工程师,主要是在Linux下对公司的源代码以及项目发布进行管理.4个月接触了好多新知识,也对各种工具的集成使用搞得云里来雾里去的,所以打算自己搭建一套环境,进行测试. ...

  2. Memcached服务器安装、配置、使用详解

    管理memcached服务 启动Memcached 一般情况下,简单地可以使用类似如下形式,启动Memcached服务: /usr/local/bin/memcached -d -m 64 -I 20 ...

  3. Lucene基础(二)--索引的操作

    索引的操作 我们建立所有就是要达到快速检索的目的,对数据能够方面便的查找,和数据库类似,索引也有自己的相关增删改查的操作. 在索引的增删改查中,增删改属于写操作,主要是有IndexWrite提供的方法 ...

  4. CODEVS 3285 转圈游戏

    [题目描述] n 个小伙伴(编号从 0 到 n-1)围坐一圈玩游戏.按照顺时针方向给 n 个位置编号,从0 到 n-1.最初,第 0 号小伙伴在第 0 号位置,第 1 号小伙伴在第 1 号位置,……, ...

  5. wordpress mobile templates

    http://themeforest.net/category/wordpress/mobile http://themeforest.net/item/monolith-wp-theme-for-b ...

  6. webkit私有css3属性 -webkit-overflow-scrolling:touch;

    -webkit-overflow-scrolling:touch;/*允许独立的滚动区域和触摸回弹*/ 这个属性可以提高滚动的平滑度

  7. 映像备份与恢复管理工具Easy Image X使用说明

    Easy Image X(简称EIX)是一个支持Ghost映像(.gho)和ImageX映像(.wim)的映像管理工具,具有友好的图形界面,仅需几步简单操作即可完成映像备份与恢复工作.维护时使用最多的 ...

  8. BT5之网络配置

    输入ifconfig命令,可以查看当前IP地址设置情况.查看路由表的命令(用来检查默认网关是否设置正确):netstat -r 一.让BT5自动获取IP地址 自动获取IP地址,使用dhclient命令 ...

  9. UVA 12647 Balloon

    这是一个线段树的题目: 我记得一个月前在cf上也做过一个类似的题目: #include<cstdio> #include<cstring> #include<algori ...

  10. const变量的存储区及修改权限

    转自const变量的存储区及修改权限 [cpp] view plaincopy const int a = 1; int *p = const_cast<int*>(&a); *p ...