forked from Shubham28/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNUMOFPAL.cpp
50 lines (40 loc) · 823 Bytes
/
NUMOFPAL.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
#include <vector>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#define FOR(A,B,C) for(int A=B;A<C;A++)
#define EFOR(A,B,C) for(int A=B;A<=C;A++)
#define RFOR(A,B,C) for(int A=B;A>=C;A--)
#define VI vector<int>
#define VB vector<bool>
#define PB(A,B) A.push_back(B);
#define SZ(A) int(A.size())
using namespace std;
int main()
{
char inp[1050];
scanf("%s",inp);
int N=strlen(inp);
vector< VB >pal;
FOR(row,0,N+2)
PB(pal,VB(N+2-row,false));
FOR(row,0,N) pal[row][0]=1;
FOR(len,1,N)
FOR(pos,0,N-len){
if(inp[pos]!=inp[pos+len])
pal[pos][len]=false;
else {
if(len==1)
pal[pos][len]=true;
else
pal[pos][len]=pal[pos+1][len-2];
}
}
int ans=0;
FOR(r,0,N) FOR(c,0,N-r)
ans+=pal[r][c];
printf("%d\n",ans);
return 0;
}