hdu4618(KMP+动态规划)
来源:互联网 发布:linux考试试题 编辑:程序博客网 时间:2024/06/07 07:17
Palindrome Sub-Array
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 317 Accepted Submission(s): 166
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.
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
15 101 2 3 3 2 4 5 6 7 81 2 3 3 2 4 5 6 7 81 2 3 3 2 4 5 6 7 81 2 3 3 2 4 5 6 7 81 2 3 9 10 4 5 6 7 8
Sample Output
4本题在比赛的时候没有想到好的方法,索性没做,赛后相结合KMP算法运用动态规划思想,不了能力太弱,也没能动手,结果就写了一个5重循环,竟能过后来索性提交了几次,得到了一些无关技巧的小技巧,裸函数、宏定义、内联函数对运行时间的影响#include<iostream>#include<cstdio>using namespace std;//#define Min(a,b) a<b?a:b//#define Max(a,b) a>b?a:bconst int MAX=300+10;int da[MAX][MAX];//宏定义Max(a,b),Min(a,b),运行时间为512Ms//直接写裸函数int Min(int a,int b),int Max(int a,int b),运行时间为656Ms//写内联函数inline int Min(int a,int b),inline int Max(int a,int b),运行时间为525Msint Min(int a,int b){return a<b?a:b;}int Max(int a,int b){return a<b?b:a;}inline int Judge(int x,int y,int len){int i,j,k;for(k=y;k<=y+len-1;k++){for(i=x,j=x+len-1;i<=j;i++,j--){if(da[i][k]!=da[j][k])return 0;}}for(k=x;k<=x+len-1;k++){for(i=y,j=y+len-1;i<=j;i++,j--){if(da[k][i]!=da[k][j])return 0;}}return len;}int main(){int cas,i,j,n,m,ans,len,tmp;cin>>cas;while(cas--){scanf("%d%d",&n,&m);for(i=0;i<n;i++){for(j=0;j<m;j++)scanf("%d",&da[i][j]);}ans=0;for(i=0;i<n;i++){for(j=0;j<m;j++){len=Min(n-i,m-j)+1;do{tmp=Judge(i,j,len);ans=Max(ans,tmp);}while(--len);}}printf("%d\n",ans);}return 0;}
- hdu4618(KMP+动态规划)
- hdu4618
- 【jzoj4886】【字符串】【动态规划】【kmp】
- timus 1002. Phone Numbers(KMP&动态规划)
- 【动态规划】【KMP】HDU 5763 Another Meaning
- Counting the String 动态规划 + KMP
- HDU3336Count the string(KMP+动态规划)
- 动态规划和字符串匹配(KMP、AC自动机)
- HDOJ3336 Count the string 【KMP前缀数组】+【动态规划】
- A*、Dijkstra、动态规划、红黑树、优先搜索、KMP
- |Hdu 3336|KMP|动态规划|Count the string
- 动态规划!!!动态规划!!!
- [BZOJ 1009] HNOI 2008 GT考试 · 动态规划+矩阵乘法+KMP
- 动态规划及空间压缩 ,串的模式匹配(KMP) Implement strStr()(leetcode)
- 100道动态规划——38 HDU 5763 Another Meaning KMP + DP
- hdu4618 Palindrome Sub-Array
- hdu4618 Palindrome Sub-Array
- HDU4618 Palindrome Sub-Array
- The Joel Test: 12 Steps to Better Code
- font resize demo
- extjs4 tab 样式修改
- 严重: Exception sending context initialized event to listener instance of class
- 设计模式之迭代器模式
- hdu4618(KMP+动态规划)
- 推荐四款浏览器兼容性测试工具
- 【7gyy】系统能不能自动登录呢?设置方法是什么?
- 内存管理 比较全
- 一起学shell(一):合并文件夹下所有文件
- Object-c学习之路十(NSNumber&NSValue)
- 字符串的最长回文字串
- uva 350 Pseudo-Random Numbers(模拟)
- hdu 1130 How Many Trees?