您的位置:首页 > 其它

vijos-p1057 2008.11.6

2016-02-05 13:29 323 查看
vijos-p1057 2008.11.6

搜索 vijos-p1057--不要受分类的误导,上面说是dp,但用搜的,一次就ac了 Has comments

描述 Description

永恒の灵魂最近得到了面积为n*m的一大块土地(高兴ING^_^),他想在这块土地上建造一所房子,这个房子必须是正方形的。

但是,这块土地并非十全十美,上面有很多不平坦的地方(也可以叫瑕疵)。这些瑕疵十分恶心,以至于根本不能在上面盖一砖一瓦。

他希望找到一块最大的正方形无瑕疵土地来盖房子。

不过,这并不是什么难题,永恒の灵魂在10分钟内就轻松解决了这个问题。

现在,您也来试试吧。

输入格式 Input Format

输入文件第一行为两个整数n,m(1<=n,m<=1000),接下来n行,每行m个数字,用空格隔开。0表示该块土地有瑕疵,1表示该块土地完好。

输出格式 Output Format

一个整数,最大正方形的边长。

样例输入 Sample Input

44

01 1 1

11 1 0

01 1 0

11 0 1

样例输出 Sample Output

2

tips:

1. 不要受分类的误导,上面说是dp,但用搜的,一次就ac了

2. 拿到题目,就要想一想是不是能用搜的

program p1057;
const maxn=1000;
fin='in.in';fout='out.out';
var a:array[1..maxn,1..maxn]of boolean;
n,i,j,max:longint;
procedure init;
var i,j,p:longint;
begin
read(n);
for i:=1 to n do
for j:=1 to n do
begin read(p);
if p=1 then a[i,j]:=true else a[i,j]:=false;
end;
end;
function find(x,y,r:longint):boolean;
var i,j:longint;
begin
for i:=x to x+r-1 do
for j:=y to y+r-1 do
if not(a[i,j]) then exit(false);{有效的剪枝}

find:=true;
end;
function min(u1,u2:longint):longint;
begin if u1>u2 then exit(u2)else exit(u1)end;
procedure deal;
var i,j,k,t,s:longint;
begin
for i:=1 to n do
for j:=1 to n do
if a[i,j] then
begin t:=j;s:=i;
repeat inc(t) until not(a[i,t])or(t=n+1);
repeat inc(s) until not(a[s,j])or(s=n+1);
t:=min(t-j,s-i);{有效的剪枝}
for k:=1 to t do
if (find(i,j,k))and(k>max) then max:=k;
end;
writeln(max);
end;
begin init; deal;end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: