zoukankan      html  css  js  c++  java
  • UVA10617

     1 /* 
     2 题意:对一个字符串进行删除操作,有多少种方式使剩下的串是回文。 
     3 也可理解为这个串有多少回文子串。 
     4 定义 dp[i][j]为 i-j有多少个回文子串。 
     5 当str[i]==str[j],
     6 dp[i][j]=dp[i+1][j-1]+1, 因为如果把i+1至j-1都删掉,剩下的两个还是个回文。
     7 
     8 */
     9 #include<cstdio>
    10 #include<cstring>
    11 #include<algorithm>
    12 using namespace std;
    13 long long dp[70][70];
    14 char str[70];
    15 int main()
    16 {
    17     
    18     int t;
    19     scanf("%d",&t);
    20     while(t--)
    21     {
    22         scanf("%s",str);
    23         int l=strlen(str);
    24         memset(dp,0,sizeof(dp));
    25         for(int i=0;i<l;i++)
    26             dp[i][i]=1;
    27         for(int i=l-2;i>=0;i--)
    28         {
    29             for(int j=i+1;j<l;j++)
    30             {
    31                 if(str[i]==str[j]) 
    32                     dp[i][j]=dp[i+1][j-1]+1;                 
    33                 dp[i][j]+=dp[i+1][j] + dp[i][j-1] - dp[i+1][j-1];
    34             }
    35         }
    36         printf("%lld
    ",dp[0][l-1]);
    37     }
    38     return 0;
    39 }
  • 相关阅读:
    MDX函数
    OLAP + MDX
    AIOps指导
    ES Terms 聚合数据不确定性
    redis初步入门
    java写hadoop全局排序
    [工程技巧]
    python与字符集编码
    转载python2进制打包相关
    转载 大端VS小端
  • 原文地址:https://www.cnblogs.com/ember/p/4893045.html
Copyright © 2011-2022 走看看