-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1040.cpp
More file actions
41 lines (37 loc) · 774 Bytes
/
1040.cpp
File metadata and controls
41 lines (37 loc) · 774 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
//
// 1040.cpp
// 算法
//
// Created by 王怡凡 on 2017/8/28.
// Copyright © 2017年 王怡凡. All rights reserved.
//
#include <stdio.h>
#include<cstring>
const int maxn = 1010;
char S[maxn];
int dp[maxn][maxn];
int main() {
gets(S);
int len = int(strlen(S)),ans=1;
memset(dp,0,sizeof(dp));
for(int i=0;i<len;i++) {
dp[i][i]=1;
if(i<len-1) {
if(S[i]==S[i+1]) {
dp[i][i+1] = 1;
ans = 2;
}
}
}
for(int L=3;L<=len;L++) {
for(int i=0;i+L-1<len;i++) {
int j=i+L-1;
if(S[i]==S[j]&&dp[i+1][j-1]==1) {
dp[i][j]=1;
ans = L;
}
}
}
printf("%d",ans);
return 0;
}