HDU2859 Phalanx 简单DP
dp[i][j]代表以s[i][j]字符为右上角的最大对称方阵的尺寸
最左边那一列都为1,然后按列更新,代码实现比较简单,感觉有点卡时间,如果对称度很好,时间应该比较高,我只会这种了
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
char s[][];
int dp[][];
int main()
{
int n;
while(~scanf("%d",&n),n)
{
for(int i=;i<=n;i++)
scanf("%s",s[i]+);
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
dp[i][]=;
int ans=;
for(int j=;j<=n;j++)
{
for(int i=;i<=n;i++)
{
dp[i][j]=;
int l=min(j-,n-i);
for(int k=;k<=l;++k)
{
int x=i+k;
int y=j-k;
if(s[i][y]!=s[x][j])
break;
if(dp[i+][j-]>=k)dp[i][j]=k+;
}
ans=max(ans,dp[i][j]);
}
}
printf("%d\n",ans);
}
return ;
}
HDU2859 Phalanx 简单DP的更多相关文章
- HDU 1087 简单dp,求递增子序列使和最大
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- Codeforces Round #260 (Div. 1) A. Boredom (简单dp)
题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. ...
- codeforces Gym 100500H A. Potion of Immortality 简单DP
Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...
- 简单dp --- HDU1248寒冰王座
题目链接 这道题也是简单dp里面的一种经典类型,递推式就是dp[i] = min(dp[i-150], dp[i-200], dp[i-350]) 代码如下: #include<iostream ...
- poj2385 简单DP
J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB 64bit ...
- hdu1087 简单DP
I - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB ...
- poj 1157 LITTLE SHOP_简单dp
题意:给你n种花,m个盆,花盆是有顺序的,每种花只能插一个花盘i,下一种花的只能插i<j的花盘,现在给出价值,求最大价值 简单dp #include <iostream> #incl ...
- hdu 2471 简单DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2571 简单dp, dp[n][m] +=( dp[n-1][m],dp[n][m-1],d[i][k ...
- Codeforces 41D Pawn 简单dp
题目链接:点击打开链接 给定n*m 的矩阵 常数k 以下一个n*m的矩阵,每一个位置由 0-9的一个整数表示 问: 从最后一行開始向上走到第一行使得路径上的和 % (k+1) == 0 每一个格子仅仅 ...
随机推荐
- Truncating HTML attribute value in SharePoint DataFormWebPart
<xsl:value-ofdisable-output-escaping="yes"select="@Body"/>
- setPreferredSize和setSize的区别及用法
我以前很喜欢borderlayout的布局方式,每次想特别调整每个区域的大小,但是每次将一个panel放入到north或者其他4个区域时,总是达不到想要的效果,刚刚才发现原来setPreferredS ...
- Indri查询命令及Java调用并保存结果
查询参数 index Indri索引库路径.在参数文件中像/path/to/repository这样指定,在命令行中像-index=/path/to/repository这样指定.该参数可以设置多次来 ...
- shell复习笔记----入门知识
Unix 简史 UNIX 最初是由贝尔实验室(Bell Telephone Laborataries)的计算机科学研究中心开发的,第一版诞生于1970年--也就是在贝尔实验室退出Multics项目不久 ...
- DIV中TABLE居的2种方式
<html><head><title>测试页面</title></head><body><div width=" ...
- 团体程序设计天梯赛-练习集L1-010. 比较大小
L1-010. 比较大小 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 杨起帆(浙江大学城市学院) 本题要求将输入的任意3个整数从小 ...
- 让wordpress分类和标签的描述支持HTML代码
默认 WordPress 后台分类和标签的编辑页面,分类和标签的描述是不支持 HTML 代码的,我们可以通过在当前主题的 functions.php 文件添加如下代码让分类和标签的描述支持 HTML ...
- 基于Oracle OCI的数据访问C语言接口ORADBI .
基于Oracle OCI的数据访问C语言接口ORADBI cheungmine@gmail.com Mar. 22, 2008 ORADBI是我在Oracle OCI(Oracle 调用接口)基础 ...
- Maven for Myeclipse的一个常见错误 Project configuration is not up-to-date with pom.xml
使用Myeclipse开发Maven项目时,经常会发现一个错误提示: Description Resource Path Location Type Project configuration is ...
- POJ3080——Blue Jeans(暴力+字符串匹配)
Blue Jeans DescriptionThe Genographic Project is a research partnership between IBM and The National ...