简单二维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. Unable to chmod

    不能改变权限 Unable to chmod /system/build.prop.: Read-only file system 解决方式: before chmod: Code: mount -o ...

  2. php发送get、post请求获取内容的几种方法

    方法1: 用file_get_contents 以get方式获取内容 <?php $url='http://www.domain.com/'; $html = file_get_contents ...

  3. SLF4JLoggerContext cannot be cast to LoggerContext

    Getting Exception org.apache.logging.slf4j.SLF4JLoggerContext cannot be cast to org.apache.logging.l ...

  4. SQL中的左连接与右连接有什么区别,点解返回值会不同?(转)

    例子,相信你一看就明白,不需要多说 A表(a1,b1,c1) B表(a2,b2) a1 b1 c1 a2 b2 01 数学 95 01 张三 02 语文 90 02 李四 03 英语 80 04 王五 ...

  5. 转 Apache Ant 实现自动化部署

    Apache Ant 实现自动化部署 Apache Ant 实现自动化部署 http://www.netkiller.cn/journal/java.ant.html Mr. Neo Chen (陈景 ...

  6. WPF(x:Null 使用)

    <Window x:Class="TestOfNull.MainWindow" xmlns="http://schemas.microsoft.com/winfx/ ...

  7. c++运行时类型识别(rtti)

    一个简单运行时类型识别 namespace rtti_ex { /* * 类型信息基类 */ class i_type_info { public: // 判断是否是指定类型 bool is(cons ...

  8. 用for while 成绩的有效输入

    #include "stdio.h" void main() { int score,s; printf("请输入你的成绩:"); scanf("%d ...

  9. Android开发 R cannot be resolved to a variable问题的分析

    R文件是系统自动生成的,如果没出现的话,你的XML文件是不是有错误?是否之前修改过res文件夹下面.xml文件 R文件没有生成的情况有几种: 1.项目没有自动编译:这种时候只需要简单的编译一下工程就会 ...

  10. Bootstrap学习 - 全局CSS样式

    栅格Grid  <!-行(row)”必须包含在 .container (固定宽度)或 .container-fluid (100% 宽度)中-> <div class="c ...