hdu2859(dp)

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2859

来自:http://www.cnblogs.com/kuangbin/p/3228215.html

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 const int maxn=1010;
 6 int n;
 7 char p[maxn][maxn];
 8 int dp[maxn][maxn];
 9 
10 int main()
11 {
12     while(scanf("%d",&n)&&n)
13     {
14         int ans=1;
15         memset(dp,0,sizeof(dp));
16         for(int i=0;i<n;i++)
17             scanf("%s",p[i]);
18         for(int i=0;i<n;i++)
19             for(int j=0;j<n;j++)
20         {
21             if(i==0||j==n-1)  //
22             {
23                 dp[i][j]=1;
24                 continue;
25             }
26             int t1=i,t2=j;
27             while(t1>=0&&t2<n&&p[t1][j]==p[i][t2])
28             {
29                 t1--;
30                 t2++;
31             }
32             int k=i-t1;
33             dp[i][j]=min(dp[i-1][j+1]+1,k);  //
34             ans=max(ans,dp[i][j]);
35         }
36         printf("%d
",ans);
37     }
38 }
原文地址:https://www.cnblogs.com/yijiull/p/6758119.html