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;
    }
    


  • 相关阅读:
    独角戏
    开源引擎
    如何实现一个UI系统
    VC编程规范—程序员应该这样写代码
    夕阳下的熊猫香[转]
    在桌面上显示屏保
    在WinSock上使用IOCP
    结构体对齐的具体含义(#pragma pack)
    一个程序员的奋斗
    让汇编揭开死循环的神秘面纱
  • 原文地址:https://www.cnblogs.com/anhuizhiye/p/3933150.html
Copyright © 2011-2022 走看看