码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • HDU - 2859 Phalanx(DP)


    HDU - 2859 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<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

    #include<iostream>
    #include<cstring>
    using namespace std;
    const int N = 1010;
    char s[N][N];
    int dp[N][N];
    int main()
    {
    	int n;
    	while(cin>>n,n)
    	{
    		memset(dp,0,sizeof dp);
    		for(int i=1;i<=n;i++) cin>>(s[i]+1);
    		int ans=1;
    		for(int i=1;i<=n;i++)
    			for(int j=n;j>=1;j--)
    			{
    				dp[i][j]=1;
    				if(i==1||j==n) continue;
    				int l=dp[i-1][j+1];
    				for(int k=1;k<=l;k++)
    					if(s[i-k][j]==s[i][j+k]) dp[i][j]++;
    					else break;
    				ans=max(ans,dp[i][j]);	
    			}
    		cout<<ans<<endl;
    	}
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
  • 相关阅读:
    【Javascript】ajax(阿甲克斯)
    智能工作流:Spring AI高效批量化提示访问方案
    Protocol Buffers定义消息类型
    leetcode刷题:栈与队列03(有效的括号)
    前端TypeScript学习day04-交叉类型与泛型
    ti代理商:好的ti代理商有哪些分销
    今天去北京拜访了三国志游戏代理商,说说看法
    独处是一种修行
    C++:迭代器的封装思想
    基于springboot实现致远汽车租赁平台管理系统项目【项目源码+论文说明】
  • 原文地址:https://blog.csdn.net/qq_52792570/article/details/125603065
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号