题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2859

给你一个n*n的矩阵,问你最大的对称度是多少(左下右上为对称线)

dp[i][j]表示i行j列元素的最大对称度

每到一个元素的时候,往上边和右边扩展看字符最优的对称长度 与dp[i - 1][j - 1]进行比较取最优即可。

 //#pragma comment(linker, "/STACK:102400000, 102400000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int N = 1e3 + ;
int dp[N][N];
char str[N][N]; int main()
{
int n;
while(~scanf("%d", &n) && n) {
for(int i = ; i <= n; ++i) {
scanf("%s", str[i] + );
}
memset(dp, , sizeof(dp));
int res = ;
for(int i = ; i <= n; ++i) {
for(int j = n; j >= ; --j) {
int len = ;
while(str[i - len][j] == str[i][j + len] && i - len > && j + len <= n) {
++len;
}
dp[i][j] = max(, min(dp[i - ][j + ], len - ) + );
res = max(res, dp[i][j]);
}
}
printf("%d\n", res);
}
return ;
}

HDU 2859 Phalanx (dp)的更多相关文章

  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 题目大意:对称矩阵是这样的矩阵,它由“左下到右”线对称. 相应位置的元素应该相同. 例如,这里是 ...

  3. HDU 2859 Phalanx (DP)

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

  4. HDU 2859—Phalanx(DP)

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

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

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

  6. HDU 2859 Phalanx ——(DP)

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

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

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

  8. HDU 2859 Phalanx

    简单二维dp.o(n^3)效率过的.不知道有没有o(n^2)的解法. 为了方便点,先左右交换一下. dp[i][j]表示以[i,j]为左上角的最大对称矩阵长度 那么dp[i][j]=min(Max,d ...

  9. hdu 4123 树形DP+RMQ

    http://acm.hdu.edu.cn/showproblem.php? pid=4123 Problem Description Bob wants to hold a race to enco ...

随机推荐

  1. HDU 4513 吉哥系列故事——完美队形II

    变形的Manacher算法,在扩展的时候要加入限制条件,满足题目中说的从左到中间身高不减. 其他地方倒是没有什么改动.. //#define LOCAL #include <iostream&g ...

  2. IE 火狐浏览器对时间格式的兼容性;使用原型对象的方式 prototype关键字;时间格式化

    在ie中 时间格式如果用横杠来显示  "2013-05-10 19:20:59" 是可以正确识别的(如果用斜杠,IE也可以正确识别), 但是如果是火狐,则只能识别斜杠模式 &quo ...

  3. 编译安装apache+php(加常见问题解决)

    [编译apache]./configure --prefix=/usr/local/lamp/httpd -with-apr=/usr/local/apr -with-apr-util=/usr/lo ...

  4. makefile learning

    Copy:http://graybull.is-programmer.com/posts/37758.html 本文给出万能Makefile的具体实现,以及对其中的关键点进行解析.所谓C++万能Mak ...

  5. I.MX6 ov5640 camera

    /************************************************************************ * I.MX6 ov5640 camera * 说明 ...

  6. Java 图片转换为字符图 CharMaps (整理)

      /* * Java 图片转换成字符图 CharMaps (整理) * * 2016-1-2 深圳 南山平山村 曾剑锋 * * @(#)CharMaps.java 2014/1/16 * 1.这个一 ...

  7. erl0007 - erlang 远程节点连接的两种方式

    启动连接:erl -setcookie abc -name xxx@192.168.x.x -remsh xxx@192.168.x.y 退出:ctrl + g,q 参考:http://www.cnb ...

  8. scala学习笔记(1):基本语法与容器

    1 var 可变,val 不可变 var (a,b) = (10,20) 分别对a,b赋值 a=10, b=20 var a,b = (10,20)则 是a=(10,20) b=(10,20) 2 L ...

  9. ecshop 文章列表页调用描述信息啊

    1.打开 includes/lib_article.php文件 将 $sql = 'SELECT article_id, title, author, add_time, file_url, open ...

  10. openssl rsa 加解密

    <h4>1.openssl进行rsa加密解密</h4>首先介绍下命令台下openssl工具的简单使用:生成一个密钥:<pre lang="c" esc ...