Light OJ 1025 - The Specials Menu(区间DP)

时间:2023-12-17 12:51:02

题目大意:

    给你一个字符串,问有多少种方法删除字符,使得剩下的字符是回文串。
有几个规定:
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+;
const int MAXN = ;
char str[MAXN];
LL dp[MAXN][MAXN];
LL DFS(int L,int R)
{
if(L > R) return ;
if(dp[L][R]) return dp[L][R];
if(L == R) return dp[L][R] = ; dp[L][R] = DFS(L+,R) + DFS(L,R-) - DFS(L+,R-);
if(str[L] == str[R])
dp[L][R] += DFS(L+, R-) + ;
return dp[L][R];
} int main()
{
int T, cas = ;
scanf("%d", &T);
while(T --)
{
memset(dp, , sizeof(dp));
scanf("%s", str);
int len = strlen(str);
printf("Case %d: %lld\n",cas ++, DFS(,len-));
} return ;
}