-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1025.cpp
72 lines (48 loc) · 1.19 KB
/
1025.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define PI (acos(-1))
#define ct cout<<
#define cn cin>>
#define spc <<" "<<
#define nl puts("")
#define _fl(x) puts("FLAG " #x);
#define _(x) cout<< #x <<" is "<< x <<endl;
#define fs first
#define sc second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define _109 (1000000000)
#define _0(arr) memset(arr,0,sizeof ( arr ) )
#define _1(arr) memset(arr,-1,sizeof ( arr ) )
#define _ninp(n,arr) for(int i=0; i<n;i++)cin>>arr[i];
#define _nout(n,arr) for(int i=0; i<n;i++)cout<<arr[i]<<" \n"[i==n-1];
double _eps=1e-6;
string inp;
ll dp[70][70];
ll f(int i, int j){
if(j-i==1){
if(inp[i]==inp[j])
return dp[i][j]=3;
else return dp[i][j]=2;
}
if(i==j)return dp[i][j]=1;
if(dp[i][j])return dp[i][j];
if(inp[i]==inp[j]){
return dp[i][j]=f(i+1,j)+f(i,j-1)+1;
}
else {
return dp[i][j]=f(i+1,j)+f(i,j-1)-f(i+1,j-1);
}
}
int main() {
int T;
cn T;
for(int caseno=1; caseno<=T ;caseno++){
cn inp;
_0(dp);
printf("Case %d: %lld\n",caseno,f(0,inp.size()-1) );
}
return 0;
}