zoukankan      html  css  js  c++  java
  • 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
    ");
            else printf("unsolvable
    ");
        }
        return 0;
    }
    


  • 相关阅读:
    SQL获取分组第一条记录
    Highcharts中Legend动态显示点值
    Json序列化
    Xml 序列化
    Json 用法整理
    Oracle如何复制表的sql语句
    spring.net 如何让xml智能提示
    C# 属性和字段的区别
    EasyUI中Grid标题居中方法(jquery实现方法)
    Asp.net Web.Config
  • 原文地址:https://www.cnblogs.com/anhuizhiye/p/3933150.html
Copyright © 2011-2022 走看看