# UVA 题目10617 - Again Palindrome（区间DP）

A palindorme is a sequence of one or more characters that reads the same from the left as it does from
the right. For example, Z, TOT and MADAM are palindromes, but ADAM is not.
Given a sequence S of N capital latin letters. How many ways can one score out a few symbols
(maybe 0) that the rest of sequence become a palidrome. Varints that are only different by an order of
scoring out should be considered the same.
Input
The input file contains several test cases (less than 15). The first line contains an integer T that
indicates how many test cases are to follow.
Each of the T lines contains a sequence S (1 ≤ N ≤ 60). So actually each of these lines is a test
case.
Output
For each test case output in a single line an integer — the number of ways.
Sample Input
3
BAOBAB
AAAA
ABA
Sample Output
22
15

5

ac代码

 16449058 825 Walking on the Safe Side Accepted C++ 0.006 2015-11-17 08:21:59

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
long long dp[1010][1010];
char str[1005];
int main()
{
int t,c=0;
scanf("%d",&t);
while(t--)
{
scanf("%s",str);
int i,len=strlen(str),j;
for(i=0;i<len;i++)
{
dp[i][i]=1;
}
for(i=1;i<len;i++)
{
for(j=i-1;j>=0;j--)
{
dp[j][i]=(dp[j+1][i]+dp[j][i-1]-dp[j+1][i-1]);
if(str[i]==str[j])
{
dp[j][i]+=dp[j+1][i-1]+1;
}
}
}
printf("%lld\n",dp[0][len-1]);
}
}


#### Uva 10617 Again Palindrome(区间dp)

2015-01-26 20:49:35

#### UVA 10617 Again Palindrome

2016-02-10 01:39:23

#### UVA 10617 - Again Palindrome

2015-03-16 14:04:20

#### UVa 10617 - Again Palindrome

2013-05-05 20:35:46

#### uva 10617 - Again Palindrome

2014-08-04 18:46:01

#### UVA 10617 Again Palindrome

2014-06-05 15:32:51

#### UVA - 10617 Again Palindrome

2013-09-19 10:11:44

#### UVa:10617 Again Palindrome

2013-12-31 13:01:37

#### UVA　10617 - Again Palindrome

2012-10-25 13:18:45

#### uva 10617 Again Palindrome

2011-11-29 22:38:54