hdu2859---Phalanx

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

/*************************************************************************
    > File Name: hdu2859.cpp
    > Author: ALex
    > Mail: [email protected]
    > Created Time: 2015年02月14日 星期六 16时31分45秒
 ************************************************************************/

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;

const int N = 1010;
int dp[N][N];
char mat[N][N];

int main ()
{
    int n;
    while (~scanf("%d", &n), n)
    {
        for (int i = 1; i <= n; ++i)
        {
            scanf("%s", mat[i] + 1);
            for (int j = 1; j <= n; ++j)
            {
                dp[i][j] = 1;
            }
        }
        for (int i = 1; i <= n; ++i)
        {
            for (int j = 1; j <= n; ++j)
            {
                int m = dp[i - 1][j + 1];
                bool flag = true;
                int x;
                for (int k = 1; k <= m; ++k)
                {
                    if (mat[i - k][j] == mat[i][j + k])
                    {
                        continue;
                    }
                    else
                    {
                        x = k;
                        flag = false;
                        break;
                    }
                }
                if (!flag)
                {
                    dp[i][j] = x;
                }
                else
                {
                    dp[i][j] = m + 1;
                }
            }
        }
        int ans = -1;
        for (int i = 1; i <= n; ++i)
        {
            for (int j = 1; j <= n; ++j)
            {
                ans = max (ans, dp[i][j]);
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}
时间: 2024-10-13 18:12:54

hdu2859---Phalanx的相关文章

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

layout: post title: 「kuangbin带你飞」专题十二 基础DP author: "luowentaoaa" catalog: true tags: mathjax: true - kuangbin - 动态规划 传送门 A.HDU1024 Max Sum Plus Plus 题意 给你N个数,然后你分成M个不重叠部分,并且这M个不重叠部分的和最大. 思路 动态规划最大m字段和,dp数组,dp[i][j]表示以a[j]结尾的,i个字段的最大和 两种情况:1.第a[j

[2016-03-29][HDU][2859][Phalanx]

时间:2016-03-29 15:53:01 星期二 题目编号:[2016-03-29][HDU][2859][Phalanx] 分析:dp[i][j]表示以 (i,j)为左下角 #include <cstdio> #include <algorithm> using namespace std; const int maxn = 1000 + 10; char a[maxn][maxn]; int dp[maxn][maxn],ans,n; void func(int x,int

HDU 2859&mdash;Phalanx(DP)

Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u 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 e

Phalanx (hdu 2859)

http://acm.hdu.edu.cn/showproblem.php?pid=2859 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 996    Accepted Submission(s): 468 Problem Description Today is army day, but the servicemen are b

HDU - 2859 Phalanx

题意:求/直线的对称矩阵最大多大 思路:DP 每个点就是了 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAXN = 1200; int dp[MAXN][MAXN]; char str[MAXN][MAXN]; int n; int main() { while (scanf(&quo

动规-HDU-2859

http://acm.hdu.edu.cn/showproblem.php?pid=2859 Phalanx 给定一个n*m的字符矩阵,求最大以副对角线对称的子方阵行数. 解题报告 思路 对于给定字符矩阵M: 记以元素M[i][j]为左下角的最大副对角线对称子方阵行数为dp[i][j]. 假设已经求得dp[i-1][j+1],欲求dp[i][j],则需要以dp[i-1][j+1]为上界,判断从M[i][j]为左下角开始的M[i][k]与M[k][j]有多少个连续相同即可. 那么就可以两层循环遍历

Q - Phalanx HDU 2859 ( dp )

Q - Phalanx Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Practice HDU 2859 Description Today is army day, but the servicemen are busy with the phalanx for the celebration of the 60th anniversary of the PRC. A pha

【学术篇】NOIP2017 d2t3 列队phalanx splay做法

我可去他的吧.... ==============先胡扯些什么的分割线================== 一道NOIP题我调了一晚上...(其实是因为昨晚没有找到调试的好方法来的说...) 曾经我以为我写完了然后全WA 0分 发现 2 1 2 1 1 1 1 这组数据能把我卡掉(我都不知道怎么过样例的)... 然后就开始调就精神崩溃就放弃治疗就划水就过去了一下午和一晚上... 今天我立(砾)志要完成这道题. 上luogu打卡 两个号(不要问我为啥两个号)分别: 然后说我调不出WA的题我就很绝望

hdu2859 dp

题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2859 题意:输入一个数n,接下来是一个由n*n个字母组成的矩阵,求以左下到右上的线为轴的最大对称阵的大小. 思路:就是dp,,,我最大的感悟就是dp要是想明白了,代码贼简单,想不懂就是死难..思路么,看下面的图就懂了. 代码: #include<iostream> #include<cstdio> #include<algorithm> #include<

HDU 2859 Phalanx (dp)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2859 给你一个n*n的矩阵,问你最大的对称度是多少(左下右上为对称线) dp[i][j]表示i行j列元素的最大对称度 每到一个元素的时候,往上边和右边扩展看字符最优的对称长度 与dp[i - 1][j - 1]进行比较取最优即可. 1 //#pragma comment(linker, "/STACK:102400000, 102400000") 2 #include <algori