Phalanx

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 363    Accepted Submission(s): 170

Problem Description
Today is army day, but the servicemen are busy with the phalanx for the celebration of the 60th anniversary of the PRC.
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
There are several test cases in the input file. Each case starts with an integer n (0<n<=1000), followed by n lines which has n character. There won’t be any blank spaces between characters or the end of line. The input file is ended with a 0.
 
Output
Each test case output one line, the size of the maximum symmetrical sub- matrix.
 
Sample Input
3
abx
cyb
zca
4
zaba
cbab
abbc
cacq
0
 
Sample Output
3
3
 
Source
 
Recommend
gaojie
 

对于每个字符看该列以上和该行右侧的字符匹配量,如果匹配量大于右上角记录下来的矩阵大小,就是右上角的数值+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)的更多相关文章

  1. hdu(2859)——Phalanx(dp)

    题意: 如今有一个n*n的矩阵,然后每一个格子中都有一个字母(大写或小写组成).然后询问你如今最大的对称子矩阵的边长是多少.注意这里的对角线是从左下角到右上角上去的. 思路: 这道题我自己写出了dp的 ...

  2. HDU 2859—Phalanx(DP)

    Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description Today i ...

  3. HDU 2859 Phalanx ——(DP)

    感觉是个n^3的dp,只是可能上界比较松吧..转移见代码.值得注意的一个地方是如果n是1,那么在for里面是不会更新答案的,因此ans要初始化为1. 代码如下: #include <stdio. ...

  4. HDU 2859 Phalanx(对称矩阵 经典dp样例)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2859 Phalanx Time Limit: 10000/5000 MS (Java/Others)  ...

  5. 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 ...

  6. HDU 3008 Warcraft(DP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3008 题目大意:人有100血和100魔法,每秒增加 t 魔法(不能超过100).n个技能,每个技能消耗 ...

  7. hdu 2059 龟兔赛跑(dp)

    龟兔赛跑 Problem Description 据说在很久很久以前,可怜的兔子经历了人生中最大的打击——赛跑输给乌龟后,心中郁闷,发誓要报仇雪恨,于是躲进了杭州下沙某农业园卧薪尝胆潜心修炼,终于练成 ...

  8. HDU 4832 Chess (DP)

    Chess Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  9. HDU 4945 2048(dp)

    题意:给n(n<=100,000)个数,0<=a[i]<=2048 .一个好的集合要满足,集合内的数可以根据2048的合并规则合并成2048 .输出好的集合的个数%998244353 ...

随机推荐

  1. 【字符串处理算法】字符串包含的算法设计及C代码实现【转】

    转自:http://blog.csdn.net/zhouzhaoxiong1227/article/details/50679587 版权声明:本文为博主原创文章,对文章内容有任何意见或建议,欢迎与作 ...

  2. Linux 入门记录:十七、Linux 命令行文本/文件处理工具

    一.文件浏览 cat 查看文件内容 more 以翻页形式查看文件内容(只能向下翻页) less 以翻页形式查看文件内容(可以上下翻页) head 查看文件的头几行(默认10行) tail 查看文件的尾 ...

  3. 2017多校第8场 HDU 6138 Fleet of the Eternal Throne 思维,暴力

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6138 题意:给了初始区间[-1,1],然后有一些操作,可以r加上一个数,l减掉一个数,或者同时操作,问 ...

  4. swift中闭包的循环引用

    首先我们先创造一个循环引用 var nameB:(()->())? override func viewDidLoad() { super.viewDidLoad() let bu = UIBu ...

  5. C基础 常用设计模式粗解

    引言 面向对象, 设计模式是现代软件开发基石. C的面向过程已经很简洁, 但不代表C就没有面向对象.(libuv框架中C面向对象用的很多) 因为思想是互通的.全当熟悉一下那些常用的设计模式.先假定有一 ...

  6. Leetcode 之Binary Tree Preorder Traversal(42)

    树的先序遍历.定义一个栈,先压入中间结点并访问,然后依次压入右.左结点并访问. vector<int> preorderTraversal(TreeNode *root) { vector ...

  7. tinyhttpd ------ C 语言实现最简单的 HTTP 服务器

    工作流程: 1>服务器启动,在指定端口或随机选取端口绑定httpd服务. 2>收到一个http请求时(其实就是listen端口accept的时候),派生一个线程运行accept_reque ...

  8. Jquery动态添加元素并给元素增加onchange相应

    动态添加元素: $select = $("<select></select>"); $("<option></option> ...

  9. LeetCode239. Sliding Window Maximum

    Given an array nums, there is a sliding window of size k which is moving from the very left of the a ...

  10. Hadoop 学习【一】 安装部署

    目标:测试Hadoop的集群安装 参考文档: [1]http://hadoop.apache.org/docs/r2.8.0/hadoop-project-dist/hadoop-common/Sin ...