Phalanx

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1542    Accepted Submission(s): 757

Problem Description

Today is army day, but the servicemen are busy with the phalanx for the celebration of the 60th anniversary of the PRC.
A phalanx is a matrix of size n*n, each element is a character (a~z or A~Z), standing for the military branch of the servicemen on that position.
For some special requirement it has to find out the size of the max symmetrical sub-array. And with no doubt, the Central Military Committee gave this task to ALPCs.
A symmetrical matrix is such a matrix that it is symmetrical by the “left-down to right-up” line. The element on the corresponding place should be the same. For example, here is a 3*3 symmetrical matrix:
cbx
cpb
zcc
 

Input

There are several test cases in the input file. Each case starts with an integer n (0<n<=1000), followed by n lines which has n character. There won’t be any blank spaces between characters or the end of line. The input file is ended with a 0.
 

Output

Each test case output one line, the size of the maximum symmetrical sub- matrix.
 

Sample Input

3
abx
cyb
zca
4
zaba
cbab
abbc
cacq
0
 

Sample Output

3
3
 

Source

 
题意:找给出的方阵中,以左下到右上方向为对称轴的最大对称子方阵。
题解:dp[i][j]表示以ch[i][j]格子为左下角的最大对称子方阵。dp[i][j] = min(dp[i-1][j+1]+1, 从(i,j)点向上、右方向匹配的对称数)
 //2017-04-20
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int N = ;
char ch[N][N];
int dp[N][N]; int main()
{
int n;
while(scanf("%d", &n)!=EOF && n)
{
for(int i = ; i < n; i++)
scanf("%s", ch[i]);
int ans = ;
for(int i = ; i < n; i++)
{
for(int j = n-; j >= ; j--)
{
if(i == || j == n-)
{
dp[i][j] = ;
continue;
}
int u, r, cnt = ;
for(int k = ; k <= dp[i-][j+]; k++){
u = i-k;
r = j+k;
if(ch[u][j] == ch[i][r])cnt++;
else break;
}
dp[i][j] = min(dp[i-][j+]+, cnt);
if(ans < dp[i][j])ans = dp[i][j];
}
}
printf("%d\n", ans);
} return ;
}

HDU2859(KB12-Q DP)的更多相关文章

  1. HDU 5907 Find Q dp

    Find Q 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5907 Description Byteasar is addicted to the ...

  2. HDU2859 Phalanx 简单DP

    dp[i][j]代表以s[i][j]字符为右上角的最大对称方阵的尺寸 最左边那一列都为1,然后按列更新,代码实现比较简单,感觉有点卡时间,如果对称度很好,时间应该比较高,我只会这种了 #include ...

  3. hdu1087 dp

    题意:给定一串数字,要求选取一个严格递增的子序列,使序列和最大. dp[i] 表示以 i 为结尾的子序列的最大和,dp[i] = max{dp[j]+a[i]}(j 从 0 到 i-1),dp[0]是 ...

  4. 【bzoj4513】储能表【数位DP】

    本来是想去学数位DP,作死挑了这道题,爆炸... 听说正确姿势应该是去做bzoj4521[手机],听说迪克们当场都A了,Orz 然后对于4513,我只想说,一.脸.懵.逼 首先,我是无论如何都无法想到 ...

  5. 2014 Super Training #1 F Passage 概率DP

    原题: HDU 3366   http://acm.hdu.edu.cn/showproblem.php?pid=3366 本来用贪心去做,怎么都WA,后来看网上原来是一个DP题. 首先按P/Q来做排 ...

  6. DP:Islands and Bridges(POJ 2288)

    2015-09-21 造桥基建工程 题目大意,就是有n座岛和k座桥,要你找一条哈密顿圈(找完所有的岛,并且每个岛只经过一次),当经过一座岛就加上岛的价值,如果两岛联通,则加上两座岛的价值之积,如果三座 ...

  7. CF 149D Coloring Brackets 区间dp ****

    给一个给定括号序列,给该括号上色,上色有三个要求 1.只有三种上色方案,不上色,上红色,上蓝色 2.每对括号必须只能给其中的一个上色 3.相邻的两个不能上同色,可以都不上色 求0-len-1这一区间内 ...

  8. HDU 4258 Covered Walkway 斜率优化DP

    Covered Walkway Problem Description   Your university wants to build a new walkway, and they want at ...

  9. BZOJ 3156: 防御准备 斜率优化DP

    3156: 防御准备 Description   Input 第一行为一个整数N表示战线的总长度. 第二行N个整数,第i个整数表示在位置i放置守卫塔的花费Ai. Output 共一个整数,表示最小的战 ...

  10. [kuangbin带你飞]专题二十二 区间DP

            ID Origin Title   17 / 60 Problem A ZOJ 3537 Cake   54 / 105 Problem B LightOJ 1422 Hallowee ...

随机推荐

  1. MariaDB 数据类型与运算符(4)

    MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可MariaDB的目的是完全兼容MySQL,包括API和命令行,MySQL由于现在闭源了,而能轻松成为MySQ ...

  2. Android自定义组合控件详细示例 (附完整源码)

    在我们平时的Android开发中,有时候原生的控件无法满足我们的需求,或者经常用到几个控件组合在一起来使用.这个时候,我们就可以根据自己的需求创建自定义的控件了,一般通过继承View或其子类来实现. ...

  3. 调用notify()后,当前线程执行完synchronized块中的所有代码才会释放锁

    package com.pinnet.test; public class Demo { public static void main(String[] args) { Demo demo = ne ...

  4. centos7上mysql5.6版本主从复制

    做主从复制实验: 第一步:主服务器上操作 1.修改主服务器master: [root@localhost ~]# vim /etc/my.cnf server_id = 1  //[必须]服务器唯一I ...

  5. postgresql-pg_prewarm数据预加载。

    pg_prewarm数据预加载. http://francs3.blog.163.com/blog/static/405767272014419114519709/   https://www.kan ...

  6. 【liferay】6、可配置式cookie

    问题提出 项目运行中,cookie的作用一般是起着一个不可或缺的权限控制或者认证的作用,但是如果是多系统交互,cookie是由别的系统生成,本系统对接的话,那么这个cookie就会 成为项目测试的一个 ...

  7. 学习推荐-Postgresql学习手册

    Postgresql之旅: http://www.cnblogs.com/stephen-liu74/archive/2012/06/08/2315679.html postgresql逻辑结构+权限 ...

  8. odoo开发笔记 -- odoo源码解析

    odoo 源码解析:http://blog.csdn.net/weixin_35737303

  9. (转)centos 7 Tomcat 8.5 的安装及生产环境的搭建调优

    原文:https://www.cnblogs.com/linhankbl/articles/9149804.html#top JVM菜鸟进阶高手之路七(tomcat调优以及tomcat7.8性能对比) ...

  10. Bash算术运算

    使用let命令 let let let let let let let 使用expr命令 - ` # + ` # \* ` # / ` # / ` # − \* ` # +` # + -*· # -* ...