hdu 2859 Phalanx (最大对称子矩阵)
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
题意:找到最大对称的矩阵
每次只需求最外面一层对称个数sum,再和右上角对称矩阵大小加一取最小就行,就求出当前小矩阵的最大对称矩阵。最后取个所有对称矩阵大小的最大值就行。
dp[i][j] = min(sum,dp[i-1][j+1]+1);
#include <cstdio>
#include <map>
#include <iostream>
#include<cstring>
#include<bits/stdc++.h>
#define ll long long int
#define M 6
using namespace std;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int moth[]={,,,,,,,,,,,,};
int dir[][]={, ,, ,-, ,,-};
int dirs[][]={, ,, ,-, ,,-, -,- ,-, ,,- ,,};
const int inf=0x3f3f3f3f;
const ll mod=1e9+;
int n;
char G[][];
int dp[][];
int main(){
ios::sync_with_stdio(false);
while(cin>>n&&n){
char a;
for(int i=;i<=n;i++)
for(int j=;j<=n;j++){
cin>>a;
if(a>='A'&&a<='Z')
a+=;
G[i][j]=a;
}
memset(dp,,sizeof(dp));
int ans=-inf;
for(int i=;i<=n;i++)
for(int j=n;j>=;j--){
int x=i; int y=j;
int sum=;
while(x>=&&y<=n&&G[x][j]==G[i][y]){
x--; y++;
sum++;
}
dp[i][j]=min(sum,dp[i-][j+]+);
ans=max(ans,dp[i][j]);
}
cout<<ans<<endl;
}
}
hdu 2859 Phalanx (最大对称子矩阵)的更多相关文章
- 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)
题意: 如今有一个n*n的矩阵,然后每一个格子中都有一个字母(大写或小写组成).然后询问你如今最大的对称子矩阵的边长是多少.注意这里的对角线是从左下角到右上角上去的. 思路: 这道题我自己写出了dp的 ...
- HDU 2859 Phalanx(二维DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2859 题目大意:对称矩阵是这样的矩阵,它由“左下到右”线对称. 相应位置的元素应该相同. 例如,这里是 ...
- HDU 2859 Phalanx (dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2859 给你一个n*n的矩阵,问你最大的对称度是多少(左下右上为对称线) dp[i][j]表示i行j列元 ...
- HDU 2859—Phalanx(DP)
Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description Today i ...
- 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.o(n^3)效率过的.不知道有没有o(n^2)的解法. 为了方便点,先左右交换一下. dp[i][j]表示以[i,j]为左上角的最大对称矩阵长度 那么dp[i][j]=min(Max,d ...
- HDU 2859 Phalanx ——(DP)
感觉是个n^3的dp,只是可能上界比较松吧..转移见代码.值得注意的一个地方是如果n是1,那么在for里面是不会更新答案的,因此ans要初始化为1. 代码如下: #include <stdio. ...
- 【HDU - 2859 】Phalanx (dp 最大对称子图)
Phalanx 先搬翻译 Descriptions: 给你一个矩阵,只由小写或大写字母构成.求出它的最大对称子矩阵的边长. 其中对称矩阵是一个k*k的矩阵,它的元素关于从左下角到右上角的对角线对称.例 ...
随机推荐
- PHP常见错误汇总
日常开发和调试的时候,经常会遇到一些错误,光怪陆离的不知所以,所以,特此将错误汇总一下,借鉴!!! 1. 原因分析: 一般可能是该文件出现了问题,检查一下代码和格式,是否出现开始的地方出现了空格,或 ...
- 开发神器之phpstorm破解与日常使用
PhpStorm 是 JetBrains 公司开发的一款商业的 PHP 集成开发工具,旨在提高用户效率,可深刻理解用户的编码,提供智能代码补全,快速导航以及即时错误检查. PhpStorm可随时帮助用 ...
- sql之cursor的简介和字符串拆分(split)与游标的使用
字符串拆分(split)与游标的使用 CREATE TABLE Plates ( ,), ) NOT NULL, [BusinessId] INT NOT NULL, ) ),),), SELECT ...
- CentOS 6.4 源码安装MySQL 5.6
1.安装前准备工作 1.1 必备的包 gcc/g++ :MySQL 5.6开始,需要使用g++进行编译.cmake :MySQL 5.5开始,使用cmake进行工程管理,cmake需要2.8以上版本. ...
- [转帖]SAP S/4 HANA与SAP Business Suite/R3(ECC)的区别
SAP S/4 HANA与SAP Business Suite/R3(ECC)的区别 https://blog.csdn.net/zhongguomao/article/details/5351520 ...
- CIFS 与 SMB 有什么区别?
CIFS 与 SMB 有什么区别? https://www.getnas.com/2018/11/30/cifs-vs-smb/ 网络协议 一知半解 学习一下挺好的.. 记得 win2019 已经废弃 ...
- WPF设置软件界面背景为MediaElement并播放视频
在我们的常见的软件界面设计中我们经常会设置软件的背景为SolidColorBrush或者LinerColorBrush.RadialGradientBrush 等一系列的颜色画刷为背景,有时我们也会使 ...
- rediret 加/与不加/的区别
- HDU4035 Maze 【树形DP】【期望DP】
题目分析: 以前一直不会这个方法, 我好菜啊. 转移分为三个部分,一个是直接成功,一个是转移到E1,还有一个是转移到自己周围的一圈儿点. 如果是叶子那么只能转移到父亲,如果不是叶子可以把非叶子的转移代 ...
- Codeforces997C Sky Full of Stars 【FMT】【组合数】
题目大意: 一个$n*n$的格子,每个格子由你填色,有三种允许填色的方法,问有一行或者一列相同的方案数. 题目分析: 标题的FMT是我吓人用的. 一行或一列的问题不好解决,转成它的反面,没有一行和一列 ...