Palindrome subsequence
Problem Description
In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence
#include<iostream>
#include<iomanip>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;
#define mod 10007
char str[1005];
int dp[1005][1005];
int main()
{
int t, i, j, k, len;
int cnt = 1;
scanf("%d", &t);
//getchar();
while (t--)
{
scanf("%s", str);
len = strlen(str);
for (int 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] + mod) % mod;
if (str[i] == str[j])
{
dp[j][i] = (dp[j][i] + dp[j + 1][i - 1] + 1 + mod) % mod;
}
}
}
printf("Case %d: %d\n", cnt++, dp[0][len - 1]);
}
return 0;
}