HDU2859(KB12-Q DP)
Phalanx
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1542 Accepted Submission(s): 757
Problem 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
Sample Output
Source
//2017-04-20
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int N = ;
char ch[N][N];
int dp[N][N]; int main()
{
int n;
while(scanf("%d", &n)!=EOF && n)
{
for(int i = ; i < n; i++)
scanf("%s", ch[i]);
int ans = ;
for(int i = ; i < n; i++)
{
for(int j = n-; j >= ; j--)
{
if(i == || j == n-)
{
dp[i][j] = ;
continue;
}
int u, r, cnt = ;
for(int k = ; k <= dp[i-][j+]; k++){
u = i-k;
r = j+k;
if(ch[u][j] == ch[i][r])cnt++;
else break;
}
dp[i][j] = min(dp[i-][j+]+, cnt);
if(ans < dp[i][j])ans = dp[i][j];
}
}
printf("%d\n", ans);
} return ;
}
HDU2859(KB12-Q DP)的更多相关文章
- HDU 5907 Find Q dp
Find Q 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5907 Description Byteasar is addicted to the ...
- HDU2859 Phalanx 简单DP
dp[i][j]代表以s[i][j]字符为右上角的最大对称方阵的尺寸 最左边那一列都为1,然后按列更新,代码实现比较简单,感觉有点卡时间,如果对称度很好,时间应该比较高,我只会这种了 #include ...
- hdu1087 dp
题意:给定一串数字,要求选取一个严格递增的子序列,使序列和最大. dp[i] 表示以 i 为结尾的子序列的最大和,dp[i] = max{dp[j]+a[i]}(j 从 0 到 i-1),dp[0]是 ...
- 【bzoj4513】储能表【数位DP】
本来是想去学数位DP,作死挑了这道题,爆炸... 听说正确姿势应该是去做bzoj4521[手机],听说迪克们当场都A了,Orz 然后对于4513,我只想说,一.脸.懵.逼 首先,我是无论如何都无法想到 ...
- 2014 Super Training #1 F Passage 概率DP
原题: HDU 3366 http://acm.hdu.edu.cn/showproblem.php?pid=3366 本来用贪心去做,怎么都WA,后来看网上原来是一个DP题. 首先按P/Q来做排 ...
- DP:Islands and Bridges(POJ 2288)
2015-09-21 造桥基建工程 题目大意,就是有n座岛和k座桥,要你找一条哈密顿圈(找完所有的岛,并且每个岛只经过一次),当经过一座岛就加上岛的价值,如果两岛联通,则加上两座岛的价值之积,如果三座 ...
- CF 149D Coloring Brackets 区间dp ****
给一个给定括号序列,给该括号上色,上色有三个要求 1.只有三种上色方案,不上色,上红色,上蓝色 2.每对括号必须只能给其中的一个上色 3.相邻的两个不能上同色,可以都不上色 求0-len-1这一区间内 ...
- HDU 4258 Covered Walkway 斜率优化DP
Covered Walkway Problem Description Your university wants to build a new walkway, and they want at ...
- BZOJ 3156: 防御准备 斜率优化DP
3156: 防御准备 Description Input 第一行为一个整数N表示战线的总长度. 第二行N个整数,第i个整数表示在位置i放置守卫塔的花费Ai. Output 共一个整数,表示最小的战 ...
- [kuangbin带你飞]专题二十二 区间DP
ID Origin Title 17 / 60 Problem A ZOJ 3537 Cake 54 / 105 Problem B LightOJ 1422 Hallowee ...
随机推荐
- linux 使用进程管理工具 supervisor
1.supervisor是使用python进行开发的运行在linux服务器上的进程管理工具 老版本的supervisor需要运行在python2环境,如果需要使用supervisor管理python3 ...
- 回车符与换行符问题——C语言
回车符(carriage return,’\r’)与换行符 (line feed,’\n’) 从上面可以看出换行对应的ASCII码值是10,回车符对应的ASCII码值是13,需要注意的是用户按下回车键 ...
- Vim使用Vundle安装代码补全插件(YouCompleteMe)
安装 Vundle 它的使用方法很简单,安装一个插件只需要在 ~/.vimrc 按照规则中添加 Plugin 的名称,某些需要添加路径,之后在 Vim 中使用:PluginInstall既可以自动化安 ...
- 遗忘Windows Server 2008R2密码的处理方法
遗忘Windows Server 2008R2的处理方法 有的时候,我们会由于各种原因忘掉了服务器密码,比如服务器太多,太杂什么的,或直接是被人黑掉了,这个时候我们想要登录,发现我们已经没有办法了,其 ...
- 分享:基于Dracula+Zenburn 自定制的pycharm主题配色文件
显示效果: PS:彩色配色,一是可以提高平时写代码的乐趣,另一个是,对视力相对比较好. 配置方法: 1. 在你本地的操作系统里,找到pycharm安装的时候,默认在C盘创建的文件夹colors:C:\ ...
- git中多账号切换问题的解决方案(转)
作者:知乎用户链接:https://www.zhihu.com/question/23028445/answer/416231632来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请 ...
- ListView中的TextView实现跑马灯效果
1.TextView首先添加android:ellipsize="marquee" android:marqueeRepeatLimit="marquee_forev ...
- 解决Redisson出现Failed to instantiate [org.redisson.api.RedissonClient]: Factory method 'create' threw exception; nested exception is java.lang.ArrayIndexOutOfBoundsException: 0的问题
一.背景 最近项目中使用了redisson的哨兵模式来作为redis操作的客户端,然后一个意外出现了,启动报:Failed to instantiate [org.redisson.api.Redis ...
- PHP之高性能I/O框架:Libevent(一)
Libevent 是一个用C语言编写的.轻量级的开源高性能I/O框架,支持多种 I/O 多路复用技术: epoll. poll. dev/poll. select 和 kqueue 等:支持 I/O, ...
- spring boot 与 thymeleaf (3): 设置属性、条件、遍历、局部变量、优先级、内联语法
前面记录了 thymeleaf 基本表达式, 这里继续看一下其他功能. 一. 设置属性值 这里的controller, html框架 还是沿用上一篇的部分. html: <div class=& ...