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 ...
随机推荐
- Yii 1.1.17 三、数据库连接、定义模型、数据查询、验证登录、SESSION使用与URL生成
一.数据库连接 1.配置连接参数 在database.php里面开启: 'db' => array( 'connectionString' => 'mysql:host=127.0.0.1 ...
- 【bzoj4695】最假女选手
zcy的励志故事.jpg 傻逼zcy突然想立一个flag,写一个segment-tree-beats的题娱乐一下 于是他就想起了这道题. 他打算今晚写完 然后光是写他就写的头昏脑涨,还犯了询问写反这种 ...
- canvas制作柱形图/折线图/饼状图,Konva写动态饼状图
制作饼状图 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- leetcode 之Swap Nodes in Pairs(21)
不允许通过值来交换,在更新指针时需要小心. ListNode *swapNodes(ListNode* head) { ListNode dummy(-); dummy.next = head; fo ...
- 【hdoj_2189】来生一起走(母函数)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2189 本题的数学模型如下: 分解的问题,常用母函数求解,这里要求每个"硬币"的价值必须 ...
- zookeeper编程入门系列之zookeeper实现分布式进程监控和分布式共享锁(图文详解)
本博文的主要内容有 一.zookeeper编程入门系列之利用zookeeper的临时节点的特性来监控程序是否还在运行 二.zookeeper编程入门系列之zookeeper实现分布式进程监控 三. ...
- SGU 263. Towers
各种操作: put x c:表示在第 x 列上增加 c 个积木(c>0). tput t x c:表示在塔 t 的第 x 列上增加 c 个积木(c>0). towers:询问共有几座塔. ...
- Vue结合原生js实现自定义组件自动生成
就目前三大前端主流数据驱动框架(vue,ng,react)而言,均具有创建自定义组件的api,但都是必须先做到事先写好挂载点,这个挂载点可以是原有静态元素标签也可以是自定义模板:对于多种组件通过同一数 ...
- DOM方法index()相关问题(为何$(this).index(this)是错误的 )
写jQuery的时候遇到一个关于index()的问题,查找相关资料后,解决了,把自己的想法写在下面. index() 方法返回指定元素相对于其他指定元素的 index 位置. 完全语法为:$(sele ...
- Flexigrid默认是可以选择多行
1.Flexigrid默认是可以选择多行,那么如何设置其只能选一行呢?今天看了看Flexigrid的源码,发现有个属性可以控制: $(this).click(function (e) { var ob ...