HDU 2859 Phalanx (DP)
Phalanx
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 363 Accepted Submission(s): 170
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
对于每个字符看该列以上和该行右侧的字符匹配量,如果匹配量大于右上角记录下来的矩阵大小,就是右上角的数值+1,否则就是这个匹配量。
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
using namespace std; int dp[][];
char str[][]; int main()
{
int n;
while(scanf("%d",&n) == && n)
{
for(int i = ;i < n;i++)
scanf("%s",str[i]);
int ans = ;
for(int i = ;i < n;i++)
for(int j = ;j < n;j++)
{
if(i == || j == n-)
{
dp[i][j] = ;
continue;
}
int t1 = i, t2 = j;
while(t1 >= && t2 < n && str[t1][j] == str[i][t2])
{
t1--;
t2++;
}
t1 = i - t1;
if(t1 >= dp[i-][j+]+)dp[i][j] = dp[i-][j+]+;
else dp[i][j] = t1;
ans = max(ans,dp[i][j]);
}
printf("%d\n",ans);
}
return ;
}
HDU 2859 Phalanx (DP)的更多相关文章
- hdu(2859)——Phalanx(dp)
题意: 如今有一个n*n的矩阵,然后每一个格子中都有一个字母(大写或小写组成).然后询问你如今最大的对称子矩阵的边长是多少.注意这里的对角线是从左下角到右上角上去的. 思路: 这道题我自己写出了dp的 ...
- HDU 2859—Phalanx(DP)
Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description Today i ...
- HDU 2859 Phalanx ——(DP)
感觉是个n^3的dp,只是可能上界比较松吧..转移见代码.值得注意的一个地方是如果n是1,那么在for里面是不会更新答案的,因此ans要初始化为1. 代码如下: #include <stdio. ...
- HDU 2859 Phalanx(对称矩阵 经典dp样例)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2859 Phalanx Time Limit: 10000/5000 MS (Java/Others) ...
- HDU 4433 locker(DP)(2012 Asia Tianjin Regional Contest)
Problem Description A password locker with N digits, each digit can be rotated to 0-9 circularly.You ...
- HDU 3008 Warcraft(DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3008 题目大意:人有100血和100魔法,每秒增加 t 魔法(不能超过100).n个技能,每个技能消耗 ...
- hdu 2059 龟兔赛跑(dp)
龟兔赛跑 Problem Description 据说在很久很久以前,可怜的兔子经历了人生中最大的打击——赛跑输给乌龟后,心中郁闷,发誓要报仇雪恨,于是躲进了杭州下沙某农业园卧薪尝胆潜心修炼,终于练成 ...
- HDU 4832 Chess (DP)
Chess Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 4945 2048(dp)
题意:给n(n<=100,000)个数,0<=a[i]<=2048 .一个好的集合要满足,集合内的数可以根据2048的合并规则合并成2048 .输出好的集合的个数%998244353 ...
随机推荐
- 在Linux中使用C语言实现控制流保护(CFG)【转】
转自:http://www.codesec.net/view/537311.html 一.前言 最近版本的windows有一个新的缓解措施叫做控制流保护(CFG).在一个非直接调用之前――例如,函数指 ...
- hadoop安装 伪分布
伪分布hadoop 安装总结 准备,在配置中hadoop用的9000端口,如果有其它软件用着这个端口,建议更换后再进行下面配置,以避免出现错误.比如php-fpm经常使用9000端口. 一.下载jdk ...
- HDU 6183 Color it 线段树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6183 题意: 有四种操作: 0:清除所有点 1 x y c : 给点(x, y)添加一种颜色c(颜色不 ...
- lnmp的安装--php
1.下载php源码 wget http://cn2.php.net/distributions/php-5.6.3.tar.gz tar zxvf php-5.6.3.tar.gz cd php-5. ...
- C++11空指针: nullptr
参考[C++11]新特性--引入nullptr NULL 在C++中, 经常会用到空指针, 一般用NULL表示空指针, 但是NULL却是这样定义的 #ifndef NULL #ifdef __cplu ...
- 六十 数据库访问 使用SQLAlchemy
数据库表是一个二维表,包含多行多列.把一个表的内容用Python的数据结构表示出来的话,可以用一个list表示多行,list的每一个元素是tuple,表示一行记录,比如,包含id和name的user表 ...
- PHP通过mysqli连接mysql数据库
数据库连接的天龙八步: 1.连接数据库 连接:mysqli_connect 2.成功与否判断 连接错误号:mysqli_connect_errno 连接错误信息:mysqli_connect_erro ...
- python spyder 今天突然打不开了【已解决】
python spyder 我是设置开机启动的,先出现dos窗口,然后是蜘蛛网,后面就什么都没有了.然后百度了半天,在csdn看到一篇文章,试了一下,内牛满面! 方法:C:\Documents and ...
- SyntaxError: Non-ASCII character '\xe7' in file 9.py on line 13, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
解决方法: #!/usr/bin/python #-*-coding:utf-8-*-
- 洛谷——P1177 【模板】快速排序
P1177 [模板]快速排序. 题目描述 利用快速排序算法将读入的N个数从小到大排序后输出. 快速排序是信息学竞赛的必备算法之一.对于快速排序不是很了解的同学可以自行上网查询相关资料,掌握后独立完成. ...