-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathLightOj 1025.cpp
More file actions
176 lines (137 loc) · 3.76 KB
/
LightOj 1025.cpp
File metadata and controls
176 lines (137 loc) · 3.76 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include<bits/stdc++.h>
#define pause system("pause");
#define FOR(s,e,inc) for(int i=s;i<=e;i+=inc)
#define mod 1000000007
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())//vector must be sorted
#define inf 1<<30
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define F first
#define S second
#define sz(x) ((int)x.size())
#define sqr(x) ( (x)* (x) )
#define eps 1e-9
#define lcm(x,y) (abs(x) /gcd(x,y))* abs(y)
#define on(x,w) x|(1<<w)
#define check(x,w) (x&(1<<w))
#define all(x) (x).begin(),(x).end()
#define pf printf
#define sf scanf
#define pi acos(-1.0)
#define reset(x,v) memset(x,v,sizeof(x));
#define AND &&
#define OR ||
#define what_is(x) cerr<<#x<<" is "<<x<<"\n";
typedef long long ll;
typedef unsigned long long llu;
using namespace std;
template<class T>
inline T mod_v(T num)
{
if(num>=0)
return num%mod;
else
return (num%mod+mod)%mod;
}
template<class T>
inline T gcd(T a,T b)
{
a=abs(a);
b=abs(b);
while(b) b ^= a ^= b ^= a %= b;
return a;
}
template<class T>
T fast_pow(T n , T p)
{
if(p==0) return 1;
if(p%2)
{
T g=mod_v ( mod_v(n) * mod_v(fast_pow(n,p-1)) );
return g;
}
else
{
T g=fast_pow(n,p/2);
g=mod_v( mod_v(g) * mod_v(g) ) ;
return g;
}
}
template<class T>
inline T modInverse(T n)
{
return fast_pow(n,mod-2);
}
bool equalTo ( double a, double b ){ if ( fabs ( a - b ) <= eps ) return true; else return false; }
bool notEqual ( double a, double b ){if ( fabs ( a - b ) > eps ) return true; else return false; }
bool lessThan ( double a, double b ){ if ( a + eps < b ) return true; else return false; }
bool lessThanEqual ( double a, double b ){if ( a < b + eps ) return true; else return false;}
bool greaterThan ( double a, double b ){if ( a > b + eps ) return true;else return false;}
bool greaterThanEqual ( double a, double b ){if ( a + eps > b ) return true;else return false;}
#define debug(args...) {dbg,args; cerr<<endl;}
struct debugger{
template<typename T> debugger& operator , (const T& v){
cerr<<v<<" ";
return *this;
}
}dbg;
int nextInt() { int n; scanf("%d", &n); return n; }
long long nextLong() { long long n; scanf("%lld", &n); return n; }
void print(int n){ printf("%d", n); }
void println(int n){ printf("%d\n", n); }
void println(long long n){ printf("%lld\n", n); }
template<class T>
inline int in(register T& num)
{
register char c=0;
num=0;
bool n=false;
while(c<33)c=getchar();
while(c>33){
if(c=='-')
n=true;
else num=num*10+c-'0';
c=getchar();
}
num=n?-num:num;
return 1;
}
/******* ! Code start from here ! *******/
ll dp[62][62][2][2][2] ;
string s;
ll re(int i,int j,int ok,int f1,int f2){
if(i>j) return ok;
if(i==j){
if(ok) return 1 + ((f1 or f2)==1?0:1) ;
else return 1;
}
ll &res = dp[i][j][ok][f1][f2] ;
if(res!=-1) return res;
res = 0;
if(s[i]==s[j])
res+=re(i+1,j-1,1,0,0);
if(!f1)
res+=re(i+1,j,ok,0,1);
if(!f2)
res+=re(i,j-1,ok,1,0);
if(!f1 and !f2)
res+=re(i+1,j-1,ok,0,0);
return res;
}
int main()
{
// std::ios_base::sync_with_stdio(false);
#ifdef kimbbakar
freopen ( "E:/Code/in.txt", "r", stdin );
// freopen ( "E:/Code/out.txt", "w", stdout );
#endif
int t,tcase=1;
in(t);
while(t--){
cin>>s;
reset(dp,-1);
pf("Case %d: %lld\n",tcase++,re(0,sz(s)-1,0,0,0 ) );
}
return 0;
}