vijos-p1057 2008.11.6

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.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值