program JednickovaPodmatice; {Urceni velikosti maximalni podmatice ze samych jednicek v zadane matici nul a jednicek} const Max = 20; {maximalni velikost zkoumane matice} var A: array[1..Max,1..Max] of integer; {zkoumana matice} N, M: integer; {velikost matice} I, J: integer; {poloha leveho horniho rohu} K: integer; {sloupec praveho horniho rohu} Min: integer; {minimum z delek sloupcu jednicek} Vel: integer; {velikost prave zkoumane podmatice} MaxVel: integer; {maximalni velikost podmatice z 1} Dalsi: Boolean; {zkoumat dalsi pravy horni roh?} begin {Vstup dat:} write('Rozmery matice: '); readln(N, M); writeln('Obsah matice po radcich:'); for I:=1 to N do for J:=1 to M do read(A[I,J]); {Predvypocet:} for J:=1 to M do for I:=N-1 downto 1 do if A[I,J] = 1 then A[I,J] := A[I,J] + A[I+1,J]; {Vlastni vypocet:} MaxVel := 0; for I:=1 to N do for J:=1 to M do if A[I,J] > 0 then {levy horni roh podmatice A[I,J]} begin K := J; {pravy horni roh podmatice A[I,K]} Min := A[I,J]; Vel := Min; {sirka podmatice = 1, vyska = Min} if Vel > MaxVel then MaxVel := Vel; {nasli jsme vetsi podmatici z 1} if K = M then Dalsi := false {neni kam pokracovat} else begin K := K+1; Dalsi := A[I,K] > 0 end; while Dalsi do {zkoumani dalsich pravych hornich rohu} begin if A[I,K] < Min then Min := A[I,K]; Vel := Min * (K-J+1); {velikost nove podmatice} if Vel > MaxVel then MaxVel := Vel; if K = M then Dalsi := false {neni kam pokracovat} else begin K := K+1; Dalsi := A[I,K] > 0 end end end; {Vysledek:} write('Velikost maximalni podmatice ze samych jednicek: '); writeln(MaxVel) end.