-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhuiwen.cpp
More file actions
42 lines (38 loc) · 945 Bytes
/
huiwen.cpp
File metadata and controls
42 lines (38 loc) · 945 Bytes
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
#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <math.h>
#include <stdlib.h>
#define INF 99999999
using namespace std;
int dp[1010][1010];
char buffer[1010];
int main(int argc, char* argv[])
{
//freopen("input.txt", "r", stdin);
int TC, C, len;
int i, j, k;
cin>>TC;
for( C = 1; C <= TC; C++)
{
scanf("%s", buffer);
len = strlen(buffer);
memset(dp, 0, sizeof(dp));
for(i = 0; i<len; i++)
dp[i][i] = 1;
for(i=1; i < len; i++) {
for(j = 0; j+i < len; j++) {
dp[j][j+i] += dp[j][j+i-1] + 1;
for(k = j; k < j + i; k++) {
if(buffer[k]==buffer[j+i])
dp[j][j+i] += dp[k+1][j+i-1] + 1;
}
dp[j][j+i] %= 100007;
}
}
cout<<"Case #"<<C<<": "<<dp[0][len-1]<<endl;
}
return 0;
}