简单二维dp。o(n^3)效率过的。不知道有没有o(n^2)的解法。

为了方便点,先左右交换一下。

dp[i][j]表示以[i,j]为左上角的最大对称矩阵长度

那么dp[i][j]=min(Max,dp[i+1][j+1])+1;

其中Max是以[i,j]为起点,i这一行和j这一列最长公共前缀的长度

#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std; const int maxn=+;
char Map[maxn][maxn];
int dp[maxn][maxn];
int n; int main()
{
while(~scanf("%d",&n))
{
if(!n) break;
for(int i=; i<n; i++) scanf("%s",Map[i]);
for(int i=; i<n; i++)
for(int j=; j<n/; j++)
swap(Map[i][j],Map[i][n-j-]); memset(dp,,sizeof dp); int ans=;
for(int i=n-; i>=; i--)
{
for(int j=n-; j>=; j--)
{
int Max=;
for(int len=;; len++)
{
if(i+len>=n||j+len>=n||Map[i][len+j]!=Map[len+i][j])
{
Max=len;
break;
}
}
Max--;
dp[i][j]=min(Max,dp[i+][j+])+;
ans=max(ans,dp[i][j]);
}
}
printf("%d\n",ans);
}
return ;
}

HDU 2859 Phalanx的更多相关文章

  1. HDU 2859 Phalanx(对称矩阵 经典dp样例)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2859 Phalanx Time Limit: 10000/5000 MS (Java/Others)  ...

  2. HDU 2859 Phalanx (dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2859 给你一个n*n的矩阵,问你最大的对称度是多少(左下右上为对称线) dp[i][j]表示i行j列元 ...

  3. HDU 2859 Phalanx(二维DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2859 题目大意:对称矩阵是这样的矩阵,它由“左下到右”线对称. 相应位置的元素应该相同. 例如,这里是 ...

  4. hdu 2859 Phalanx (最大对称子矩阵)

    Problem Description Today is army day, but the servicemen are busy with the phalanx for the celebrat ...

  5. HDU 2859 Phalanx (DP)

    Phalanx Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  6. HDU 2859—Phalanx(DP)

    Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description Today i ...

  7. hdu(2859)——Phalanx(dp)

    题意: 如今有一个n*n的矩阵,然后每一个格子中都有一个字母(大写或小写组成).然后询问你如今最大的对称子矩阵的边长是多少.注意这里的对角线是从左下角到右上角上去的. 思路: 这道题我自己写出了dp的 ...

  8. HDU 2859 Phalanx ——(DP)

    感觉是个n^3的dp,只是可能上界比较松吧..转移见代码.值得注意的一个地方是如果n是1,那么在for里面是不会更新答案的,因此ans要初始化为1. 代码如下: #include <stdio. ...

  9. Phalanx (hdu 2859)

    http://acm.hdu.edu.cn/showproblem.php?pid=2859     Time Limit: 10000/5000 MS (Java/Others)    Memory ...

随机推荐

  1. nuget 服务器崩溃

    1,首先是500错误 2.服务器处理请求时遇到错误.异常消息为"对路径" bin"目录的访问被拒绝." 对bin目录添加User用户读写权限

  2. doclint in jdk8

    http://blog.joda.org/2014/02/turning-off-doclint-in-jdk-8-javadoc.html Turning off doclint in JDK 8 ...

  3. spice-vdagent

    The spice-vdagent should be running in the guest. Have you installed the spice guest tools in your w ...

  4. spice up your desktop

    https://wiki.gnome.org/Projects/GnomeShell/CheatSheet windows10用了一段时间,回来看着gnome3-shell是那么的恶心,翻来翻去重新整 ...

  5. android全屏和取消全屏 旋转屏幕

    全屏 getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 取消全屏 getWindow().clearFlags(Win ...

  6. sql求日期

    2.求以下日期SQL: 昨天 select convert(varchar(10),getdate() - 1,120) 明天 select convert(varchar(10),getdate() ...

  7. myeclipse 调试JSP页面

    http://jingyan.baidu.com/article/636f38bb1ef1aad6b9461048.html

  8. wpf 类似TextBlock外观的Button的样式

    <Style x:Key="noborderbtnStyle" TargetType="{x:Type Button}"> <Setter P ...

  9. UVA 1400 线段树

    input n m 1<=n,m<=500000 a1 a2 ... an |ai|<=1e9 m行查询 每行一对a b output 对于每对a b输出区间[a,b]中最小连续和x ...

  10. Learning Java characteristics (Java in a Nutshell 6th)

    Java characteristics: Java .class files are machine-independent, including the endianness. Java .cla ...