Phalanx
Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
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
Output
Sample Input
abx
cyb
zca
4
zaba
cbab
abbc
cacq
0
Sample Output
3
/*
题意:给你一个n*n的字符矩阵,让你求出,最大的对称矩阵的边长,对角线是从左下角到右上角 初步思路:递推 ,从右上角向下递推,dp[i][j]表示是以(i,j)为左下角的最大对称矩阵的边长,这样就得到状态转移方程:
从(i,j)开始向上,向右遍历,如果相等的长度>dp[i-1][j+1]的话,dp[i][j]=dp[i-1][j+1]+1,否则的话就是
dp[i-1][j+1]; #错误:还在找错误原因
*/
#include <bits/stdc++.h>
using namespace std;
int n;
char s[][];
int dp[][];
int maxn=;
void init(){
memset(dp,,sizeof dp);
maxn=;
}
int main(){
// freopen("in.txt","r",stdin);
while(scanf("%d",&n)!=EOF&&n){
init();
for(int i=;i<=n;i++){
scanf("%s",s[i]+);
}
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(i==||j==n){
dp[i][j]=;
continue;
}
int a=i,b=j;//表示向上向右遍历的长度
while(a>=&&b<=n&&s[a][j]==s[i][b]){
a--;
b++;
}
// cout<<dp[i][j]<<" ";
a=i-a;
if(a>=dp[i-][j+]+){
dp[i][j]=dp[i-][j+]+;
}else{
dp[i][j]=a;
}
maxn=max(dp[i][j],maxn);
}
// cout<<endl;
}
// for(int i=1;i<=n;i++){
// for(int j=1;j<=n;j++){
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
printf("%d\n",maxn);
}
return ;
}
Phalanx的更多相关文章
- HDU2859 Phalanx (动态规划)
Today is army day, but the servicemen are busy with the phalanx for the celebration of the 60th anni ...
- hdu 2859 Phalanx (最大对称子矩阵)
Problem Description Today is army day, but the servicemen are busy with the phalanx for the celebrat ...
- Phalanx (hdu 2859)
http://acm.hdu.edu.cn/showproblem.php?pid=2859 Time Limit: 10000/5000 MS (Java/Others) Memory ...
- HDU 2859 Phalanx (DP)
Phalanx Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 2859 Phalanx(对称矩阵 经典dp样例)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2859 Phalanx Time Limit: 10000/5000 MS (Java/Others) ...
- HDU 2859—Phalanx(DP)
Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description Today i ...
- 【学术篇】NOIP2017 d2t3 列队phalanx splay做法
我可去他的吧.... ==============先胡扯些什么的分割线================== 一道NOIP题我调了一晚上...(其实是因为昨晚没有找到调试的好方法来的说...) 曾经我以 ...
- 【HDU - 2859 】Phalanx (dp 最大对称子图)
Phalanx 先搬翻译 Descriptions: 给你一个矩阵,只由小写或大写字母构成.求出它的最大对称子矩阵的边长. 其中对称矩阵是一个k*k的矩阵,它的元素关于从左下角到右上角的对角线对称.例 ...
- HDU 2859 Phalanx (dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2859 给你一个n*n的矩阵,问你最大的对称度是多少(左下右上为对称线) dp[i][j]表示i行j列元 ...
随机推荐
- ASP.NET Core 2.0 使用支付宝PC网站支付
前言 最近在使用ASP.NET Core来进行开发,刚好有个接入支付宝支付的需求,百度了一下没找到相关的资料,看了官方的SDK以及Demo都还是.NET Framework的,所以就先根据官方SDK的 ...
- E - 钱币兑换问题
在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很多种兑法.请你编程序计算出共有多少种兑法. Input每行只有一个正整数N,N小于32768. Output对应每个输入,输出兑换方 ...
- pdf点击超链接后返回:alt+ 向左 /向右
pdf点击超链接后返回:alt+ 向左 /向右
- uva11806
[题意] n行m列网格放k个石子.有多少种方法?要求第一行,第一列,最后一行,最后一列必须有石子. [题解] 利用容斥原理.可以转到求"第一行.第一列.最后一行.最后一列没有石子" ...
- HTML5基础知识及相关笔记
HTML5基础 1.1HTML文件的基本结构和W3C标准 1.1.1HTML简介 HTML是一种描述网页的语言,一种超文本标记的语言! 1.1.2HTML文件的基本结构 头部(head) 头部是网页的 ...
- 原生JS封装animate运动框架
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8" ...
- Python实战之IO多路复用select的详细简单练习
IO多路复用 I/O多路复用指:通过一种机制,可以监视多个描述符,一旦某个描述符就绪(一般是读就绪或者写就绪),能够通知程序进行相应的读写操作. select 它通过一个select()系统调用来 ...
- c#(asp.net) 多线程示例,用于同时处理多个任务
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- 算法-找出与目标数字相同的digit组成的整数中比该数字大的数集中的最小数字
题目: 给出1个正整数,找到用与这个数字相同的digit组成的整数中比这个数字大的数集中的最小数字.比如:12352874 的结果是 12354278 分析: 这道题目的考虑目标是数组的查找与排序. ...
- 数组去重方法(ES6)
let arrayBefore = [1,3,3,2,1,5,2,1]; //去重之前的数组 Array.prototype.dedupe = function (){ //去重函数 返回去重后的数组 ...