poj 4618 暴力
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4618
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#define maxn 305
using namespace std; vector<int> G[maxn*maxn];
int a[maxn][maxn];
int maxp;
int N,M; bool find(int u,int v){
int d = G[u].size();
for(int i=;i<d;i++){
if(G[u][i] == v) return true;
}
return false;
}
bool JudgeRowPalindrome(int x1,int y1,int x2,int y2){
if(y1 >= y2) return true;
if(a[x1][y1] == a[x2][y2]){
if(find((x1)*N+y1+,(x2)*N+y2-)) return true;
if(JudgeRowPalindrome(x1,y1+,x2,y2-)){
G[x1*N+y1+].push_back(x2*N+y2-);
return true;
}
}
else return false;
}
bool JudgeColPalindrome(int x1,int y1,int x2,int y2){
if(x1 >= x2) return true;
if(a[x1][y1] == a[x2][y2]){
if(find((x1+)*N+y1,(x2-)*N+y2)) return true; if(JudgeColPalindrome(x1+,y1,x2-,y2)){
G[(x1+)*N+y1].push_back((x2-)*N+y2);
return true;
}
}
else return false; }
bool Judge(int x,int y,int len){
for(int i=x;i<x+len;i++)
if(!find(N*i+y,N*i+y+len-)) return false;
for(int i=y;i<y+len;i++)
if(!find(N*x+i,N*(x+len-)+i)) return false;
return true;
}
int main()
{
// if(freopen("input.txt","r",stdin)== NULL) {printf("Error\n"); exit(0);} int T;
cin>>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]);
}
for(int i=;i<=N*M + N+M;i++) G[i].clear(); for(int row=;row<N;row++)
for(int i=;i<M;i++)
for(int j=i+;j<M;j++){
if(find(N*row+i,N*row+j) || a[row][i] != a[row][j]) continue;
bool flag = JudgeRowPalindrome(row,i,row,j);
if(flag) G[N*row+i].push_back(N*row+j);
}
for(int col=;col<M;col++)
for(int i=;i<N;i++)
for(int j=i+;j<N;j++){
if(find(N*i+col,N*j+col) || a[i][col] != a[j][col]) continue;
bool flag = JudgeColPalindrome(i,col,j,col);
if(flag==true) G[N*i+col].push_back(N*j+col);
}
maxp = ;
for(int i=;i<N;i++)
for(int j=;j<M;j++){
if(N-i <= maxp || M-j <= maxp) continue;
if(N--i >= M--j){
for(int k=M-;k>=j+maxp;k--){
if(find(N*i+j,N*i+k)){
int p = k-j+;
if(Judge(i,j,p)){
maxp = p;
}
}
}
}
else{
for(int k=N-;k>=i+maxp;k--){
if(find(N*i+j,N*k+j)){
int p = k-i+;
if(Judge(i,j,p)){
maxp = p;
}
}
}
}
}
printf("%d\n",maxp);
}
}
poj 4618 暴力的更多相关文章
- POJ 2182/暴力/BIT/线段树
POJ 2182 暴力 /* 题意: 一个带有权值[1,n]的序列,给出每个数的前面比该数小的数的个数,当然比一个数前面比第一个数小的个数是0,省略不写,求真正的序列.(拗口) 首先想到的是从前到后暴 ...
- poj 1840 暴力+标记
Description Consider equations having the following form: a1x1 3+ a2x2 3+ a3x3 3+ a4x4 3+ a5x5 3=0 T ...
- POJ - 1426 暴力枚举+同余模定理 [kuangbin带你飞]专题一
完全想不到啊,同余模定理没学过啊,想起上学期期末考试我问好多同学'≡'这个符号什么意思,都说不知道,你们不是上了离散可的吗?不过看了别人的解法我现在会了,同余模定理介绍及运用点这里点击打开链接 简单说 ...
- POJ 1166 暴力搜索 即 枚举
e.... 米还是没有读懂题....T_T ..... e.... 这就是传说中的暴力吗....太血腥了....太暴力了...九重for循环....就这么赤裸裸的AC了.... 水是水了点..但是.. ...
- POJ 3174 暴力枚举
思路: 暴力枚举三个点 判一判 搞定 (x1*y1=x2*y2) x1.y1.x2.y2为他们两两的差 //By SiriusRen #include <cstdio> using nam ...
- POJ 2249 暴力求组合数
Binomial Showdown Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22692 Accepted: 692 ...
- Smith Numbers POJ - 1142 暴力递归枚举
题意: 给你一个数x,把这个分解成素数之积(假设是x1*x2*x3),如果 x的每一数位的和 等于 x1每一数位的和加上x2每一数位的和加上x3每一数位的和,那么他就是题目要找的数 示例: ...
- POJ 2329 (暴力+搜索bfs)
Nearest number - 2 Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3943 Accepted: 1210 De ...
- POJ 1661 暴力dp
题意略. 思路: 很有意思的一个题,我采用的是主动更新未知点的方式,也即刷表法来dp. 我们可以把整个路径划分成横向移动和纵向移动,题目一开始就给出了Jimmy的高度,这就是纵向移动的距离. 我们dp ...
随机推荐
- CentOS 7设置iptables防火墙开放proftpd端口
由于ftp的被动模式是这样的,客户端跟服务器端的21号端口交互信令,服务器端开启21号端口能够使客户端登录以及查看目录.但是ftp被动模式用于传输数据的端口却不是21,而是大于1024的随机或配置文件 ...
- OC - 19.GCD
简介 GCD(Grand Center Dispatch)是Apple为多核的并行运算提出的解决方案,纯C语言 更加适配多核处理器,且自动管理线程的生命周期,使用起来较为方便 GCD通过任务和队列实现 ...
- Spring MVC中注解 @ModelAttribute
1.@ModelAttribute放在方法之上,在当前Control内的所有方法映射多个URL的请求,都会执行该方法 @ModelAttribute public void itemsCommon(H ...
- hdoj 2041 超级阶梯
代码: #include <stdio.h>int main(){int n;int i;int m;int count;int dp[50];while(scanf("%d&q ...
- Android 新版NDK环境搭建(免Cygwin)
使用最新ndk,直接抛弃cygwin,以前做Android的项目要用到NDK就必须要下载NDK,下载安装Cygwin(模拟Linux环境用的),下载CDT(Eclipse C/C++开发插件),还要配 ...
- Apache配置域名
Apache配置域名 在WIN下安装APACHE配置虚拟目录和UNIN下基本是一样的就是修改httpd.conf1:单个IP对应单个域名例如:www.phpunion.com对应192.168.1.1 ...
- CoreLocation MKMapView
高德开发者平台 有开发指南 iOS9配置网络: <key>NSAppTransportSecurity</key> <dict> <key>NSAllo ...
- Windows开发技术的历史
原文地址:http://www.kuqin.com/windows/20090315/40172.html Windows已经有22年的历史,这22年来,微软官方主力推行的编程语言与API有四个分水岭 ...
- Little Kings
sgu223:http://acm.sgu.ru/problem.php?contest=0&problem=223 题意:n*n的格子放k个国王,一共有多少种放发. 题解:简单的状压DP. ...
- codeforces Toy Sum
题意:给你x个集合的数,然后根据求y集合的数. 思路:根据对称性,先找出对称出现的个数cnt,然后对称位置的中如果出现一个的把另一个加入到y集合中,再找出cnt个对应位置都不出现的加入到y集合中. # ...