您的位置:首页 > 其它

【DP】 HDU 2859 Phalanx

2015-02-21 14:34 302 查看
求在对角线上对称的最大子矩阵

以右上角为上一个状态

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cmath>
using namespace std;
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <deque>
#include <map>
#define cler(arr, val) memset(arr, val, sizeof(arr))
typedef long long LL;
const int MAXN = 1000100;
const int MAXM = 20000;
const int INF = 0x3f3f3f3f;
const LL mod = 10000007;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
char s[1022][1022];
int dp[1011][1011];
int main()
{
int n;
while(cin>>n,n)
{
for(int i=1;i<=n;i++)
cin>>s[i]+1;
cler(dp,0);
int ans=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==1||j==n)
dp[i][j]=1;
int x=i,y=j;
while(x>=1&&y<=n&&s[x][j]==s[i][y])
{
x--,y++;
}
if(i-x>=dp[i-1][j+1]+1)
dp[i][j]=dp[i-1][j+1]+1;
else dp[i][j]=i-x;
ans=max(ans,dp[i][j]);
}
}
cout<<ans<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: