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

InputThere 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.OutputEach 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 题意:
问最大对称矩阵,对称轴是这样的:/
思路:
dp[i][j]表示以i,j为左下角坐标的最大矩阵大小。
更新的时候向上和向右走就行了,只是感觉这个复杂度不太正常。
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<ctime>
#define fuck(x) cout<<#x<<" = "<<x<<endl;
#define ls (t<<1)
#define rs ((t<<1)+1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const int inf = 2.1e9;
const ll Inf = ;
const int mod = ;
const double eps = 1e-;
const double pi = acos(-);
char mp[][];
int dp[][];
int main()
{
int n;
int ans;
while(scanf("%d",&n)&&n){
ans=;
for(int i=;i<=n;i++){
scanf("%s",mp[i]+);
}
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
int t1=i,t2=j;
int m=dp[i-][j+];
int rec=;
for(int k=;k<=m+;k++){
t1--;t2++;
if(t1<=||t2>n){break;}
if(mp[t1][j]==mp[i][t2]){rec++;}
else break;
}
dp[i][j]=;
if(rec>dp[i-][j+]){dp[i][j]=dp[i-][j+]+;ans=max(ans,dp[i][j]);}
else dp[i][j]=rec;
}
}
printf("%d\n",ans);
}
return ;
}
												

HDU2859 Phalanx (动态规划)的更多相关文章

  1. HDU2859 Phalanx 简单DP

    dp[i][j]代表以s[i][j]字符为右上角的最大对称方阵的尺寸 最左边那一列都为1,然后按列更新,代码实现比较简单,感觉有点卡时间,如果对称度很好,时间应该比较高,我只会这种了 #include ...

  2. 「kuangbin带你飞」专题十二 基础DP

    layout: post title: 「kuangbin带你飞」专题十二 基础DP author: "luowentaoaa" catalog: true tags: mathj ...

  3. 【HDU - 2859 】Phalanx (dp 最大对称子图)

    Phalanx 先搬翻译 Descriptions: 给你一个矩阵,只由小写或大写字母构成.求出它的最大对称子矩阵的边长. 其中对称矩阵是一个k*k的矩阵,它的元素关于从左下角到右上角的对角线对称.例 ...

  4. 增强学习(三)----- MDP的动态规划解法

    上一篇我们已经说到了,增强学习的目的就是求解马尔可夫决策过程(MDP)的最优策略,使其在任意初始状态下,都能获得最大的Vπ值.(本文不考虑非马尔可夫环境和不完全可观测马尔可夫决策过程(POMDP)中的 ...

  5. 简单动态规划-LeetCode198

    题目:House Robber You are a professional robber planning to rob houses along a street. Each house has ...

  6. 动态规划 Dynamic Programming

    March 26, 2013 作者:Hawstein 出处:http://hawstein.com/posts/dp-novice-to-advanced.html 声明:本文采用以下协议进行授权: ...

  7. 动态规划之最长公共子序列(LCS)

    转自:http://segmentfault.com/blog/exploring/ LCS 问题描述 定义: 一个数列 S,如果分别是两个或多个已知数列的子序列,且是所有符合此条件序列中最长的,则 ...

  8. C#动态规划查找两个字符串最大子串

     //动态规划查找两个字符串最大子串         public static string lcs(string word1, string word2)         {            ...

  9. C#递归、动态规划计算斐波那契数列

    //递归         public static long recurFib(int num)         {             if (num < 2)              ...

随机推荐

  1. mean项目的分模块开发

    全文字版: 新建maven工程在,作为父工程用于最后集合使用,该工程不需要src,只需要一个pom.xml文件,规定一下依赖版本之类的,再建一个工具类的工程,不需要放配置文件,和工程中方法接口有关的不 ...

  2. Sql Server 获取本周周一

    SELECT DATEADD(Day,(@i+1)-(DATEPART(Weekday,getdate())+@@DATEFIRST-1)%7,getdate())

  3. SAP CRM 集类型(Set Type)与产品层次(Product Hierarchy)

    本文是产品与对象相关的部分SAP文档的翻译,不包含配置部分. 本文链接:https://www.cnblogs.com/hhelibeb/p/10112723.html 1,对象(Objects) 对 ...

  4. TortoiseGit之配置密钥

    TortoiseGit 使用扩展名为ppk的密钥,而不是ssh-keygen生成的rsa密钥.使用命令ssh-keygen -C "邮箱地址" -t rsa产生的密钥在Tortoi ...

  5. c++11のunique_lock和once_flag

    一. Unique _lock和lockguard一样,到那时比lockguard更加灵活,可以随时按照需要加锁开锁 std::unique_lock<std::mutex> locker ...

  6. day9-基础函数的学习(四)

    这几天一直赶着写写作业,博客的书写又落下了,要加油鸭,开写 今日份目录 1.内置函数 2.递归函数 开始今日份总结 1.内置函数 内置函数就是python内部包含的函数,总计有68种,不过有些事真的天 ...

  7. Linux内核入门到放弃-设备驱动程序-《深入Linux内核架构》笔记

    I/O体系结构 总线系统 PCI(Peripheral Component Interconnect) ISA(Industrial Standard Architecture) SBus IEEE1 ...

  8. [Spark][Streaming]Spark读取网络输入的例子

    Spark读取网络输入的例子: 参考如下的URL进行试验 https://stackoverflow.com/questions/46739081/how-to-get-record-in-strin ...

  9. SaxReader读取xml

    package com.java1234.action; import java.io.File; import java.util.List; import org.dom4j.Document; ...

  10. Linux(Ubuntu)使用日记(三)------git安装使用

    1. 安装 首先,确认你的系统是否已安装git,可以通过git指令进行查看,如果没有,在命令行模式下输入sudo apt-get install git命令进行安装. 2.  配置 git confi ...