zoukankan      html  css  js  c++  java
  • Light OJ 1025

    题目大意:

        给你一个字符串,问有多少种方法删除字符,使得剩下的字符是回文串。
    有几个规定:
    1.空串不是回文串
    2.剩下的字符位置不同也被视为不同的回文串。如:AA有三种回文串 A, A, AA
    ================================================================================================
     
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    #include<cmath>
    #include<queue>
    #include<vector>
    #include<map>
    using namespace std;
    typedef long long LL;
    const int INF = 1e9+7;
    const int MAXN = 255;
    char str[MAXN];
    LL dp[MAXN][MAXN];
    LL DFS(int L,int R)
    {
        if(L > R) return 0;
        if(dp[L][R]) return dp[L][R];
        if(L == R) return dp[L][R] = 1;
    
        dp[L][R] = DFS(L+1,R) + DFS(L,R-1) - DFS(L+1,R-1);
        if(str[L] == str[R])
            dp[L][R] += DFS(L+1, R-1) + 1;
        return dp[L][R];
    }
    
    int main()
    {
        int T, cas = 1;
        scanf("%d", &T);
        while(T --)
        {
            memset(dp, 0, sizeof(dp));
            scanf("%s", str);
            int len = strlen(str);
            printf("Case %d: %lld
    ",cas ++, DFS(0,len-1));
        }
    
        return 0;
    }
  • 相关阅读:
    dubbo注册zookeeper保错原因
    Django 终端打印SQL语句
    Django 的orm模型
    Django 的路由系统
    Django 开端
    前端 jq的ajax请求
    前端 后台
    前端 JQ操作
    前端 链式操作
    前端 JQ事件操作
  • 原文地址:https://www.cnblogs.com/chenchengxun/p/4908262.html
Copyright © 2011-2022 走看看