Palindrome Sub-Array

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 173    Accepted Submission(s): 80

Problem Description
  A palindrome sequence is a sequence which is as same as its reversed order. For example, 1 2 3 2 1 is a palindrome sequence, but 1 2 3 2 2 is not. Given a 2-D array of N rows and M columns, your task is to find a maximum sub-array of P rows and P columns, of which each row and each column is a palindrome sequence.
 
Input
  The first line of input contains only one integer, T, the number of test cases. Following T blocks, each block describe one test case.
  There is two integers N, M (1<=N, M<=300) separated by one white space in the first line of each block, representing the size of the 2-D array.
  Then N lines follow, each line contains M integers separated by white spaces, representing the elements of the 2-D array. All the elements in the 2-D array will be larger than 0 and no more than 31415926.
 
Output
  For each test case, output P only, the size of the maximum sub-array that you need to find.
 
Sample Input
1
5 10
1 2 3 3 2 4 5 6 7 8
1 2 3 3 2 4 5 6 7 8
1 2 3 3 2 4 5 6 7 8
1 2 3 3 2 4 5 6 7 8
1 2 3 9 10 4 5 6 7 8
 
Sample Output
4
 
Source
 
Recommend
zhuyuanchen520
 

很简单的题目

那个时候想复杂了

只要暴力过去就行了。

枚举中心点,然后扩展。

偶数和奇数行分开算

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <string>
#include <math.h>
using namespace std;
const int MAXN = ;
int a[MAXN][MAXN];
int n,m;
int calc(int x,int y,int tt)//tt=0奇数,tt=1偶数
{
int ans;
int x1,y1,x2,y2;//两个角坐标
if(tt == )
{
ans = ;
x1 = x; y1 = y;
x2 = x; y2 = y;
}
else
{
if(x+>=n || y+>=m)return ;
ans = ;
x1 = x;y1 = y;
x2 = x+;y2 = y+;
if(a[x1][y1]!=a[x2][y1]||a[x1][y1]!=a[x2][y1])
return ;
if(a[x2][y2]!=a[x2][y1]||a[x2][y2]!=a[x2][y1])
return ;
}
while()
{
x1--;y1--;
x2++;y2++;
if(x1 < || y1 < || x2 >= n || y2 >= m)
return ans;
for(int i = x1;i <= x2;i++)
if(a[i][y1]!=a[x2-i+x1][y1])
return ans;
for(int i = x1;i <= x2;i++)
if(a[i][y2]!=a[x2-i+x1][y2])
return ans;
for(int i = y1;i <= y2;i++)
if(a[x1][i]!=a[x1][y2-i+y1])
return ans;
for(int i = y1;i <= y2;i++)
if(a[x2][i]!=a[x2][y2-i+y1])
return ans;
for(int i = x1;i <= x2;i++)
if(a[i][y1]!=a[i][y2])
return ans;
for(int i = y1;i <= y2;i++)
if(a[x1][i]!=a[x2][i])
return ans;
ans += ;
}
return ans;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int T; scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i = ; i < n;i++)
for(int j = ;j < m;j++)
scanf("%d",&a[i][j]);
int ans = ;
for(int i = ;i < n;i++)
for(int j = ;j < m;j++)
{
ans = max(ans,calc(i,j,));
ans = max(ans,calc(i,j,));
}
printf("%d\n",ans); }
return ; return ;
}

HDU 4618 Palindrome Sub-Array (2013多校2 1008 暴力)的更多相关文章

  1. HDU 4632 Palindrome subsequence (2013多校4 1001 DP)

    Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65535 K (Java/ ...

  2. HDU 4691 Front compression (2013多校9 1006题 后缀数组)

    Front compression Time Limit: 5000/5000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Othe ...

  3. HDU 4679 Terrorist’s destroy (2013多校8 1004题 树形DP)

    Terrorist’s destroy Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Othe ...

  4. HDU 4671 Backup Plan (2013多校7 1006题 构造)

    Backup Plan Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total ...

  5. HDU 4667 Building Fence(2013多校7 1002题 计算几何,凸包,圆和三角形)

    Building Fence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)To ...

  6. HDU 4745 Two Rabbits (2013杭州网络赛1008,最长回文子串)

    Two Rabbits Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Tota ...

  7. HDU 4618 Palindrome Sub-Array 暴力

    Palindrome Sub-Array 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4618 Description A palindrome s ...

  8. hdu 4618 Palindrome Sub-Array

    http://acm.hdu.edu.cn/showproblem.php?pid=4618 直接DP+记忆化 虽然时间复杂度看起来是300^4 但实际执行起来要远远小于这个值 所有可以水过 代码: ...

  9. HDU 4658 Integer Partition (2013多校6 1004题)

    Integer Partition Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

随机推荐

  1. PopupWindow+ListView

    1. 获取打到数据 for (int i = 0; i < iocOutMakeMaterialSubmit.data.size(); i++) { dataListPopupWindow.ad ...

  2. 抛出自定义异常,spring AOP事务不回滚的解决方案

    spring AOP 默认对RuntimeException()异常或是其子类进行事务回滚,也就是说 事务回滚:throw new RuntimeException("xxxxxxxxxxx ...

  3. 12月2日,上海Cloud Foundry Summit, Azure Cloud Foundry 团队期待和你见面!

    12月2日,上海Cloud Foundry Summit, Azure Cloud Foundry 团队期待和你见面! 12日2日对中国Cloud Foundry的用户和开源社区来说,是极有意义的一天 ...

  4. ORACLE 临时表空间清理

    Oracle临时表空间主要用来做查询和存放一些缓冲区数据.临时表空间消耗的主要原因是需要对查询的中间结果进行排序.临时表空间的主要作用: 索引create或rebuildOrder by 或 grou ...

  5. JVM参数汇总

    一.java启动参数共分为三类: 其一是标准参数(-),所有的JVM实现都必须实现这些参数的功能,而且向后兼容:其二是非标准参数(-X),默认jvm实现这些参数的功能,但是并不保证所有jvm实现都满足 ...

  6. 顺序表的基本操作(C)

    在顺序存储结构实现基本操作:初始化.创建.插入.删除.查找.遍历.逆置.合并运算. 运行示例: 请输入线性表La的长度: 请输入线性表La中的元素(共5个) *** 此时线性表La中的元素 *** * ...

  7. echo输出空行

    rem 以下方法都可以输出空行,这十种方法分为三组,每组的效率依次递减 echo= echo, echo; echo+ echo/ echo[ echo] echo: echo. echo\

  8. Struts1与Struts2的异同

    1.都是MVC的WEB框架 2.struts1是老牌框架,应用很广泛,有很好的群众基础,使用它开发风险很小,成本更低: struts2虽然基于这个框架,但是应用群众并不多,相对不成熟,未知的风险和变化 ...

  9. Mac OS X 10.9 编译C++11

    Notice: How to compile C++ with C++ 11 support in Mac Terminal stackoverflow上面的问题 其实mac里面的不是g++而是cla ...

  10. 开扒php内核函数,第二篇 hex2bin

    从上一篇我们得知怎样把ascii变成16进制显示,这篇我们是怎样把16进制变成ascii显示 我们还是从分析开始吧 先看这个函数的介绍吧 string hex2bin ( string $data ) ...