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 ...
随机推荐
- nginx常用的超时配置说明
client_header_timeout 语法 client_header_timeout time默认值 60s上下文 http server说明 指定等待client发送一个请求头的超时时间(例 ...
- Apache Roller 5.0.3 XXE漏洞分析
下载5.0.2的版本来分析 5.0.2的war包地址 http://archive.apache.org/dist/roller/roller-5/v5.0.2/bin/roller-weblogge ...
- 在vue项目中stylus的安装及使用
Stylus是一个CSS预处理器. Stylus安装包安装: dell@DESKTOP-KD0EJ4H MINGW64 /f/gsff-frone $ cnpm install stylus --sa ...
- VM虚拟机-Ubuntu server- 桥接模式网络配置
问题描述: 在Ubuntu虚拟机安装完毕之后,网络连接采用桥接模式,对虚拟机的eth0网卡进行静态IP设置,参数配置没有问题,但网络一直没有连接成功:即:无法实现本地主机连通虚拟机(ping不通该虚拟 ...
- Facade外观模式(结构性模式)
1.系统的复杂度 需求:开发一个坦克模拟系统用于模拟坦克车在各种作战环境中的行为,其中坦克系统由引擎.控制器.车轮等各子系统构成.然后由对应的子系统调用. 常规的设计如下: #region 坦克系统组 ...
- Maven启用代理服务器访问
0.什么叫代理服务器? 代理服务器英文全称是(Proxy Server),其功能就是代理网络用户去取得网络信息.形象的说:它是网络信息的中转站. 代理服务器就好象一个大的Cache,这样就能显著提高浏 ...
- php -- 配置与安装
1.php与apache安装路径 2.安装Apache服务 httpd -k install 开启关闭重启服务 http -k start/stop/restart 3.php.ini-develop ...
- spring security的简单应用
本文只包涵spring security配置部分,不是一个完整项目,不过可以任意添加到一个web项目中,不需要对原来的程序做任何修改 部分内容来源于网络,如有雷同,毫无意外 1.xml配置文件 < ...
- j2ee高级开发技术课程第十四周
RPC(Remote Procedure Call Protocol) RPC使用C/S方式,采用http协议,发送请求到服务器,等待服务器返回结果.这个请求包括一个参数集和一个文本集,通常形成“cl ...
- 分享一个shell脚本的坑:grep匹配+wc取值 在脚本执行后的结果与手动执行结果不一致
打算在跳板机上写一个shell脚本,批量检查远程服务器上的main进程是否在健康运行中. 先找出其中一台远程机器,查看main进程运行情况 [root@two002 tmp]# ps -ef|grep ...