-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhe114.cpp
56 lines (51 loc) · 1.04 KB
/
he114.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
/**
* Author: G1
* Description: DP
*/
#include <bits/stdc++.h>
#define sl(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pi(n) printf("%d", n)
#define pl(n) printf("%lld\n", n)
#define p printf(" ")
#define pn printf("\n")
#define rep(n) for(int i=0; i<n; ++i)
#define ll long long
#define MP make_pair
using namespace std;
typedef pair<ll, pair<ll, ll> > PPI;
int t, i;
int dp[1010][1010];
char s[1010];
int sl;
ll sum=0;
int main() {
ios_base::sync_with_stdio(false);
si(t);
while(t--) {
ss(s);sum=0;
for(i=0; s[i]!='\0'; ++i);sl=i;
memset(dp, 0, sizeof dp);
for(int len=1; len<=sl; ++len) {
for(int i=1; i+len-1<=sl; ++i) {
int j=i+len-1;
if(s[i-1]==s[j-1]) {
if(i==j || i==j-1) dp[i][j]=1;
if(dp[i+1][j-1]==1) dp[i][j]=1;
}
}
}
for(int i=1; i<=sl; ++i) {
for(int j=1; j<=sl; ++j) {
//pi(dp[i][j]);p;
if(dp[i][j]==1) {
sum+=(j-i+1)*(j-i+1);
}
}
//pn;
}
pl(sum);
}
return 0;
}