lightoj 1025 - The Specials Menu - dblank

lightoj 1025 - The Specials Menu

Feuzem is an unemployed computer scientist who spends his days working at odd-jobs. While on the job he always manages to find algorithmic problems within mundane aspects of everyday life.

Today, while writing down the specials menu at the restaurant he's working at, he felt irritated by the lack of palindromes (strings which stay the same when reversed) on the menu. Feuzem is a big fan of palindromic problems, and started thinking about the number of ways he could remove letters from a particular word so that it would become a palindrome.

Two ways that differ due to order of removing letters are considered the same. And it can also be the case that no letters have to be removed to form a palindrome.
<h1>Input</h1>
Input starts with an integer T (≤ 200), denoting the number of test cases.

Each case contains a single word W (1 ≤ length(W) ≤ 60).
<h1>Output</h1>
For each case, print the case number and the total number of ways to remove letters from W such that it becomes a palindrome.



Sample Input

Output for Sample Input

3 SALADS PASTA YUMMY Case 1: 15 Case 2: 8 Case 3: 11

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
using namespace std;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f, N = 60 + 10, Mod = 1000000007;
typedef long long ll;
int pathN;
ll dpN;
char s[N];
int main()
{
int t;
cin>>t;
for(int cas = 1; cas<=t; cas++)
{
scanf("%s", s);
memset(dp, 0, sizeof(dp));
memset(path, 0, sizeof(path));
int len = strlen(s);
for(int i = 0; i<len; i++)
dpi = 1;
for(int i = len-1; i>=0; i--)
{
for(int j = i+1; j<len; j++)
{
if(s[i] == s[j])
dpi += dpi+1 + dpi  + 1;
else dpi += dpi+1 + dpi - dpi+1;
}
}
ll ans = dp0;
printf("Case %d: %lldn",cas,  ans);
}
return 0;
}