HDU 2859 Phalanx
简单二维dp。o(n^3)效率过的。不知道有没有o(n^2)的解法。
为了方便点,先左右交换一下。
dp[i][j]表示以[i,j]为左上角的最大对称矩阵长度
那么dp[i][j]=min(Max,dp[i+1][j+1])+1;
其中Max是以[i,j]为起点,i这一行和j这一列最长公共前缀的长度
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<vector>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std; const int maxn=+;
char Map[maxn][maxn];
int dp[maxn][maxn];
int n; int main()
{
while(~scanf("%d",&n))
{
if(!n) break;
for(int i=; i<n; i++) scanf("%s",Map[i]);
for(int i=; i<n; i++)
for(int j=; j<n/; j++)
swap(Map[i][j],Map[i][n-j-]); memset(dp,,sizeof dp); int ans=;
for(int i=n-; i>=; i--)
{
for(int j=n-; j>=; j--)
{
int Max=;
for(int len=;; len++)
{
if(i+len>=n||j+len>=n||Map[i][len+j]!=Map[len+i][j])
{
Max=len;
break;
}
}
Max--;
dp[i][j]=min(Max,dp[i+][j+])+;
ans=max(ans,dp[i][j]);
}
}
printf("%d\n",ans);
}
return ;
}
HDU 2859 Phalanx的更多相关文章
- HDU 2859 Phalanx(对称矩阵 经典dp样例)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2859 Phalanx Time Limit: 10000/5000 MS (Java/Others) ...
- HDU 2859 Phalanx (dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2859 给你一个n*n的矩阵,问你最大的对称度是多少(左下右上为对称线) dp[i][j]表示i行j列元 ...
- HDU 2859 Phalanx(二维DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2859 题目大意:对称矩阵是这样的矩阵,它由“左下到右”线对称. 相应位置的元素应该相同. 例如,这里是 ...
- hdu 2859 Phalanx (最大对称子矩阵)
Problem Description Today is army day, but the servicemen are busy with the phalanx for the celebrat ...
- HDU 2859 Phalanx (DP)
Phalanx Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 2859—Phalanx(DP)
Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description Today i ...
- hdu(2859)——Phalanx(dp)
题意: 如今有一个n*n的矩阵,然后每一个格子中都有一个字母(大写或小写组成).然后询问你如今最大的对称子矩阵的边长是多少.注意这里的对角线是从左下角到右上角上去的. 思路: 这道题我自己写出了dp的 ...
- HDU 2859 Phalanx ——(DP)
感觉是个n^3的dp,只是可能上界比较松吧..转移见代码.值得注意的一个地方是如果n是1,那么在for里面是不会更新答案的,因此ans要初始化为1. 代码如下: #include <stdio. ...
- Phalanx (hdu 2859)
http://acm.hdu.edu.cn/showproblem.php?pid=2859 Time Limit: 10000/5000 MS (Java/Others) Memory ...
随机推荐
- c++之模板
. 函数模板 普通函数 void Swap(int &, int &); 模板函数 template <typename T> void Swap(T &, T & ...
- 转 12C 连接CDB和PDB
来源:David Dai -- Focus on Oracle 连接到CDB 和普通实例一样的连接. 指定ORACLE_SID 以后可以使用OS认证,也可以使用密码进行连接. [oracle@Ora1 ...
- php 弹窗插件
index.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// ...
- Dynamic Performance Tables not accessible Automatic Statistics disabled for this session
使用oracle时候统计会出现这个提示 Dynamic Performance Tables not accessible Automatic Statistics disabled for this ...
- php实现json
<?PHP function __json_encode( $data ) { if( is_array($data) || is_object($data) ) { $islist = is_ ...
- 【Qt开发】修改源码文件的编码格式的小技巧 .
默认情况下,代码文件应该以utf-8的格式来存储的.而如果在代码文件的转移或者上传下载过程中,弄乱了文件的编码格式,一般会出现乱码的情况. 例如windows系统下,中文就很容易出现乱码,如下图,文件 ...
- unity LineRenderer
using UnityEngine; using System.Collections; public class Spider:MonoBehaviour { private LineRendere ...
- Light OJ - 1058 Parallelogram Counting(判定平行四边形)
Description There are n distinct points in the plane, given by their integer coordinates. Find the n ...
- GIT问题,error:src refspec master does not match any
将本地GIT版本库PUSH到一个GITHUB上一个空的版本库时可能会出现如下错误error:src refspec master does not match any原因: 本地版本库为空, 空目录不 ...
- SpringMVC中获得HttpRequest对象的方法
1. 使用@autowired注入HttpRequest 2. 在方法中直接声明形参有HttpRequest即可. 3. 使用一个Listener,然后获取.