[DP] "maximum full 0 matrix" "2015.7.9TEST" E

Source: Internet
Author: User

E
0.9 seconds, MB
"So you have at least proved that your IQ is higher than the golden sky, and that you have proved that you are not a low-intelligence child, good."
But this time, I seem to be stuck, you give me a hit. Brave boy, go and make a miracle! ”
——-by Doctor Z
It seems that Dr. Z is resolving some problems in the zvangelion, and is encountering difficulties in the middle.
Zvangelion The first machine has a r*s circuit module was infected by some UMA. In order to facilitate our use of integers
Describes the parts of each unit, that is, the module is represented by an integer matrix.
The UMA's habit is that if a n*m module S is infected (n,m>1), then it is bound to make the first
(a) (n,1) (1,m) and (n,m) the element is maintained (meaning that if the circuit is modified, it will be satisfied) to
(UMA will only infect at least 2 rows of circuit modules with at least 2 columns)
A[1][1] + a[n][m]≤a[1][m] + a[n][1]
(Note: a[i][j] denotes the number of column J of row I in the matrix)
However, who says a circuit will not be repeated infection? When a circuit is repeatedly infected, any one sub-circuit dies
Block (that is, the circuit represented by a matrix of matrices) is infected, and then this circuit can cause terrible things,
Right, that's the change! (the correct argument should be the Apostle)
Dr. Z needs to know that in this r*s circuit module, the largest area of variation (apostolic) of a suspected sub-power
What is the area of the road module?
Input
The first line is two positive integers R and S (2≤r,s≤1000), representing the circuit module size of the zvangelion.
Next to the matrix of the R row S column, an integer is used to describe the components on the R*s Circuit unit in the circuit module. Describe the use
The integers are distributed within [ -1000000,1000000].
The area of the "output" area of the sub-circuit module with the largest variation (apostolic) suspicion. If not, output 0.
"Test Sample"
Input
3 3
1 4 10
5 2 6
11 1 3
Output
9
Input
3 3
1 3 1
2 1 2
1 1 1
Output
4
Input
5 6
1 1 4 0 3 3
4 4 9 7 11 13
-3-1 4 2 8 11
1 5 9 5 9 10
4 8 10 5 8 8
Output
15
Focus on explaining the second Test sample. If the entire circuit module is suspected of mutation, then the 3*3 moment is required.
Array of 1, 2*2 matrix of a total of 4 to meet the conditions of infection. However, the 2*2 moment in the lower left and upper right corner is observed.
The array does not meet the requirements. So the largest area is neither 9 (3*3), nor 6 (2*3 or 3*2),
The 2*2 matrix in the upper left corner is suspected of mutation, so the maximum area is 4 (2*2). The mutation module of the third Test sample is
From (3,2) to the (5,6) end of the sub-module.
Test data range: 60% of the data meets R, s≤350

For the condition of infection, we can find a property:
A b C
D E F
Suppose 1.a+e<=b+d = a-b<=d-e
2.b+f<=c+e = B-c<=e-f
Can be launched A-c<=d-f =>a+f<=c+d
In this way, the problem can be simplified into one that asks for the maximum total of 0 matrices.
For 1 to r-1,1 to S-1 point if it is the upper left point of the 2*2 matrix to meet the requirements, the point is marked as 0, otherwise 1, and then generated a long r-1, wide s-1 matrix, the answer is the largest full 0 matrix.

#include <cstdio>#include <cstring>#define MAXL 1001intr,s,ans=0;intA[MAXL][MAXL];intF[MAXL][MAXL],H[MAXL],L[MAXL],RR[MAXL];voidPrework () {freopen ("Input.txt","R", stdin); Freopen ("Output.txt","W", stdout);scanf("%d%d", &r,&s); for(intI=1; i<=r;i++) for(intj=1; j<=s;j++)scanf("%d", &a[i][j]);}voidMainwork () { for(intI=1; i<=r-1; i++) for(intj=1; j<=s-1; j + +)if(a[i][j]+a[i+1][j+1]<=a[i+1][j]+a[i][j+1]) f[i][j]=0;Elsef[i][j]=1; for(intI=1; i<=r-1; i++) { for(intj=1; j<=s-1; j + +)//h[j] Indicates how many contiguous 0 are in column J of row I, and the matrix under enumeration is the height of h[j]{if(f[i][j]==0) h[j]++;Elseh[j]=0;//This one is 1 and can't go down the length.} for(intj=1; j<=s-1; j + +) {l[j]=j;first assume that the left edge of the h[j] matrix for this height is J             while(l[j]>1&& h[j]<=h[l[j]-1])//If H[J] is less than h[l[j]-1],l[j] direct expansion to l[l[j]-1]l[j]=l[l[j]-1];//Because L[L[J]-1] is already extended to the left side of L[j]-1, must have met the requirements of the} for(intj=s-1; j>=1; j--)//And expand the left zone as the practice{rr[j]=j; while(rr[j]<s-1&& h[j]<=h[rr[j]+1]) rr[j]=rr[rr[j]+1]; } for(intj=1; j<=s-1; j + +)//Find the largest matrix, because here is the indentation of the 01 matrix, calculate the area length and width to +1{if(ans< (h[j]+1) * (rr[j]-l[j]+2)) ans= (h[j]+1) * (rr[j]-l[j]+2); }    }}voidPrint () {printf("%d", ans);}intMain () {prework ();    Mainwork (); Print ();return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

[DP] "maximum full 0 matrix" "2015.7.9TEST" E

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.