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\n",ans);
37     }
38 }

 

转载于:https://www.cnblogs.com/yijiull/p/6758119.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值