Test instructions
The matrix of N*m, not 0 in each lattice is 1.
You can swap a couple of columns arbitrarily. Finally, a new matrix is obtained.
Ask what is the largest sub-rectangular area that can be obtained (this sub-rectangle must be all 1).
Ideas:
First, A[i][j] records the number of consecutive 0 from the column I, section J.
Enumerate each row as the bottom of the sub-matrix of the answer, and then sort the line a[i][j] from large to small, sweeping through the calculations.
Look at the code.
Code:
intn,m;Chartemps[1005][1005];inta[1005][1005]; intts[1005];BOOLcmpintAintb) { returnA>b;}intMain () { while(SCANF ("%d%d", &n,&m)! =EOF) {Rep (i,0, N-1) {scanf ("%s", Temps[i]); } mem (A,0); Rep (I,0, M-1)if(temps[0][i]=='0') a[0][i]=0;Elsea[0][i]=1; Rep (I,1, N-1) {Rep (J,0, M-1){ if(temps[i][j]=='1') a[i][j]=1+a[i-1][j]; } } intans=0; Rep (I,0, N-1) {Rep (J,0, M-1) ts[j]=A[i][j]; Sort (Ts,ts+m,cmp); Rep (I,0, M-1) Ans=max (ans,ts[i]* (i+1) ); } printf ("%d\n", ans); } return 0;}
HDU 2830 Matrix Swapping II (amount, sort?) )