题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2859
题意:求最大的对称矩阵
思路:从右上角到左下角进行DP
AC代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>
const int inf = 0x3f3f3f3f;//1061109567
typedef long long LL;
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
char map1[1010][1010];
int dp[1010][1010];
int main()
{
int n;
while(scanf("%d",&n) && n)
{
memset(dp,0,sizeof(dp));
for(int i=1; i<=n; i++)
scanf("%s",map1[i]+1);
int ans = 1;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=n; j++)
{
int x = i,y=j;
int temp = 0;
while(x>=1 && y<=n && map1[x][j] == map1[i][y])
{
temp++;
x--;
y++;
}
if(temp >= dp[i-1][j+1]+1)
dp[i][j] = dp[i-1][j+1]+1;
else
dp[i][j] = temp;
ans = max(ans,dp[i][j]);
}
}
printf("%d\n",ans);
}
return 0;
}