UVa 10074 - Take the Land

10074 - Take the Land

 * 

Summary
A Dynamic Programming problem. (Same with 108)

Explanation
Create matrix A[m][n],where A[i][k]- longest line containing no 1 starting from (i,k). For all (i,k) do l-width j-height for (kk=i,l=1,j=matrix[i][k];kkmatrix[kk][k]) j=matrix[kk][k]; if (j*l>max) max=j*l; }else break;

Implementations
//Created by Zaspire
 * 1) include 

int m,n,matrix[100][100];

int main {	freopen("in.txt","r",stdin); int i,k,j,kk,l,max; while (scanf("%d %d",&m,&n),m!=0||n!=0) {		max=0; for (i=0;i=0;i--) {				if (matrix[j][i]==0) k++; else k=0; matrix[j][i]=k; }		}		for (i=0;imax) max=j; for (kk=i+1,l=2;kkmatrix[kk][k]) j=matrix[kk][k]; if (j*l>max) max=j*l; }else break; }		printf("%d\n",max); }	return 0; }
 * 1) ifndef ONLINE_JUDGE
 * 1) endif

Input
6 7 0 1 1 0 1 1 0 0 0 0 0 0 1 0 1 1 0 0 0 0 1 0 1 0 1 0 0 1 1 1 0 0 0 1 0 1 1 0 1 1 0 0 6 7 0 1 1 0 1 1 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1 0 1 0 0 1 1 1 0 0 0 1 0 1 1 0 1 1 0 0 0 0

Output
6 8