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列元 ...
随机推荐
- servlet文件上传2——复合表单提交(数据获取和文件上传)
上传文件时表单enctype属性必须要更改为<enctype='multipart/form-data'>:采用post提交表单,元素需要有name属性: 利用第三方jar包(common ...
- poj3468(一维)(区间查询,区间修改)
A Simple Problem with Integers You have N integers, A1, A2, ... , AN. You need to deal with two kind ...
- bzoj1027 [HNOI2004]打鼹鼠
[HNOI2004]打鼹鼠 2014年5月2日2,8605 Description 鼹鼠是一种很喜欢挖洞的动物,但每过一定的时间,它还是喜欢把头探出到地面上来透透气的.根据这个特点阿Q编写了一个打鼹鼠 ...
- lambda表达式杂谈
var personInfo = [ { name: "张三", age: 20, gender: "male" }, { name: "李四&quo ...
- Postgresql在线备份和恢复
1.实验环境 OS: RedHat Linux Enterprisedb 6.3 DB: postgresql 9.3 PGHOME: /opt/PostgreSQL/9.3 PGDATA: /opt ...
- PHP计算上个月的开始时间和结束时间戳
$m = date('Y-m-d', mktime(0,0,0,date('m')-1,1,date('Y'))); $t = date('t',strtotime($m)); //上个月共多少天 $ ...
- python之控制台(console)颜色显示
#coding=utf-8 import ctypes,sys STD_INPUT_HANDLE = -10 STD_OUTPUT_HANDLE = -11 STD_ERROR_HANDLE = -1 ...
- 干了这杯Java之ArrayList
List存储一个有序元素合集 List接口的实现类有: ArrayList,LinkedList,Vector,Stack ArrayList一个数组型的List 默认容量为10 private st ...
- var let const 的区别
Var let const 的区别 1.Var 定义的变量存在变量提升,而了let和const不存在变量提升.即在定义的变量代码上使用该变量,var的会输出undefined,而let的会报错. 2. ...
- WebApi实现验证授权Token,WebApi生成文档等
using System; using System.Linq; using System.Web; using System.Web.Http; using System.Web.Security; ...