HDU 2859 Phalanx(对称矩阵 经典dp样例)
传送门:
http://acm.hdu.edu.cn/showproblem.php?pid=2859
Phalanx
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2792 Accepted Submission(s): 1357
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
abx
cyb
zca
4
zaba
cbab
abbc
cacq
0
3
#include<bits/stdc++.h>
using namespace std;
#define max_v 1005
char a[max_v][max_v];
int dp[max_v][max_v];
int main()
{
int n;
while(cin>>n,n)
{
memset(dp,,sizeof(dp));
getchar();
for(int i=;i<n;i++)
{
scanf("%s",&a[i]);
dp[][i]=;//初始化
}
int ans=;
for(int i=;i<n;i++)
{
for(int j=n-;j>=;j--)//右上角开始
{
int x=i-,y=j+;//上一个矩阵的左下角坐标
int num=;//对称字符个数
while(x>=&&x<n&&y>=&&y<n&&a[i][y]==a[x][j])//坐标在大矩阵内且字符对称
{
x--;//横坐标上移
y++;//纵坐标右移
num++;//对称字符数加1
}
if(num>dp[i-][j+])//判断当前矩阵是不是对称矩阵
{
dp[i][j]=dp[i-][j+]+;
}else
{
dp[i][j]=num;
}
ans=max(ans,dp[i][j]);//找对称矩阵最大阶
}
}
printf("%d\n",ans);
}
return ;
}
HDU 2859 Phalanx(对称矩阵 经典dp样例)的更多相关文章
- HDU 2859 Phalanx(二维DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2859 题目大意:对称矩阵是这样的矩阵,它由“左下到右”线对称. 相应位置的元素应该相同. 例如,这里是 ...
- HDU 1003 Max Sum --- 经典DP
HDU 1003 相关链接 HDU 1231题解 题目大意:给定序列个数n及n个数,求该序列的最大连续子序列的和,要求输出最大连续子序列的和以及子序列的首位位置 解题思路:经典DP,可以定义 ...
- 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)
题意: 如今有一个n*n的矩阵,然后每一个格子中都有一个字母(大写或小写组成).然后询问你如今最大的对称子矩阵的边长是多少.注意这里的对角线是从左下角到右上角上去的. 思路: 这道题我自己写出了dp的 ...
- HDU 2859 Phalanx ——(DP)
感觉是个n^3的dp,只是可能上界比较松吧..转移见代码.值得注意的一个地方是如果n是1,那么在for里面是不会更新答案的,因此ans要初始化为1. 代码如下: #include <stdio. ...
- hdu 2859 Phalanx (最大对称子矩阵)
Problem Description Today is army day, but the servicemen are busy with the phalanx for the celebrat ...
- hdu 2859 (二维dp)
点击打开链接 题意: 给你一个n*n的矩阵,矩阵中只含有26个小写字母,求其中最大的对称矩阵的大小 当我们算到s[i][j]时,每次我们只需要将它上方的和右方的依次比较,看是否相同 注意这里不能只比较 ...
随机推荐
- IAR使用技巧 之 快捷键批量更换指定字符(以及Keil的全局替换功能)
使用IAR(或者Keil)写/移植程序时批量更换字符 作者:李剀 出处:https://www.cnblogs.com/kevin-nancy/p/10776712.html 或者 https://b ...
- 深入redis内部之redis启动过程之二
接上文,继续分析代码 1. 设置线程安全模式 zmalloc_enable_thread_safeness();/*设置线程安全标识符为1*/ void zmalloc_enable_thread_s ...
- swpuctf-web部分学习总结
1.用优惠码 买个 X ? (1)第一步: 这道题第一步主要知道利用php的随机种子数泄露以后就可以利用该种子数来预测序列,而在题目中会返回15位的优惠码,但是必须要24位的优惠码,因此要根据15位的 ...
- Cannot initialize Cluster. Please check your configuration for mapreduce.framework.name
添加一下依赖 <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop- ...
- 8、列表:ion-list
1.基本样式 no-lines 属性 隐藏列表项之间的分割符 inset 属性 去掉 ion-list的 外边框. 默认 的 ion-list 是有外边框的. /* ---示例代码----*/ & ...
- 初学Hadoop之计算TF-IDF值
1.词频 TF(term frequency)词频,就是该分词在该文档中出现的频率,算法是:(该分词在该文档出现的次数)/(该文档分词的总数),这个值越大表示这个词越重要,即权重就越大. 例如:一篇文 ...
- bootstrap fileinput+MVC 上传多文件,保存
新增用户资料,需要用户上传多笔附件,所以就尝试用了fileinput控件,显示效果如图: 首先,先在model中定义数据模型: public partial class create { [Requi ...
- 通过js控制层的动态隐藏
<style type="text/css"> #dv1{ width:1000px; height:1000px; overflow:hidden; display: ...
- git获取别人远程dev分支上的代码
我们在使用 git clone xxx.git 下载代码的时候,获取到的只是 master上的代码 假入有个 dev 分支我们想获取上面的代码怎么办! #下载dev分支上的代码并切换到dev分支 g ...
- 常见的media断点
landscape mode是指宽度比高度宽的模式,也就是俗称的宽屏模式: portrait mode是指高度比宽度高的模式,也就是俗称的竖屏模式: /*#region SmartPhones */ ...