Bzoj 3039 Jade Toad Hall maximum sub-matrix calculation ♂ Method ②

Source: Internet
Author: User

Test Instructions:Link Method:The calculation ♂ method of maximal sub-matrix ② parsing:First of all, the monotonous stack DP is sure to be able to live, but not at all high-end! What age is this way! So how do you manifest yourself as a high-end person? The suspension method can meet your needs! What is the method of suspending the line? First of all, for the definition of the suspension line, for a n*m in the coordinate diagram of any point, its upward can extend a segment (do not hit the bad point) is called the suspension line. If the definition H[i,j] represents (i,j) the length of the suspension of the point. Then, if the point above is a bad point, then the length of the suspension is 0, the point is a bad point, the length of the suspension is 0, otherwise, the length of the hanging line of the top point plus 1. If so, then the final suspension length should be h[i,j]+1, not clear self-observation. And then, for a suspension, we want to know the size of the maximum sub-matrix, we need to translate the suspension line, that is, it can be shifted to the left to a long distance, to the right to translate many long distances, may be l[i,j] to the left to translate how much distance, R[i,j] to the right to translate many long distances, convenient statistics, We put the bad points of these two values to 0, the non-bad point of L for the first 1 points +1,r for the last one O'Clock +1, the final l+r-1 is the length of the matrix, and the suspension line is wide, so the area can be taken out. But how? First, let's assume that all l,r are for the bank, so it's easy to deal with the l,r of all points. Complexity 2nm After we enumerate all the non-bad points, at the same time as update H, update l,r, it is easy to find that the current point of L should be its top point of L with that point in its line of l of the smaller person. Let's assume that the length of the suspension is 2, so you can tell by drawing a picture. is the cable length greater than 2? Again a recursive thought. The treatment of R is the same. So the final bit (h+1) * (l+r-1) is the maximum sub-matrix area corresponding to that point. Some people may say, so the next boundary is not the furthest distance ah? But don't forget, we enumerate in order, that is, the furthest point on the lower boundary is bound to be enumerated and updated at that point. What is the difference between this algorithm and ①? Its complexity is n*m, which is obviously suitable for this method when the diagram is small. Code:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 1010using namespace STD;intL,w;intH[n][n];intLe[n][n];intRi[n][n];int MapN [N];Chars[2];intMain () {scanf("%d%d", &l,&w); for(intI=1; i<=l;i++) { for(intj=1; j<=w;j++) {scanf('%s ', s);if(s[0]==' F ')MapI [j]=1; }    } for(intI=1; i<=l;i++) { for(intj=1; j<=w;j++) {if(!MapI [j]) le[i][j]=0;Elsele[i][j]=le[i][j-1]+1; } for(intj=w;j>=1; j--) {if(!MapI [j]) ri[i][j]=0;Elseri[i][j]=ri[i][j+1]+1; }    } for(intI=1; i<=l;i++) { for(intj=1; j<=w;j++) {if(Map[I1][j]&&MapI [j]) {h[i][j]=h[i-1][j]+1; Le[i][j]=min (le[i][j],le[i-1][J]); Ri[i][j]=min (ri[i][j],ri[i-1][J]); }        }    }intans=0; for(intI=1; i<=l;i++) { for(intj=1; j<=w;j++) {Ans=max (ans, (h[i][j]+1) * (le[i][j]+ri[i][j]-1)); }    }printf("%d\n", ans*3);}

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

Bzoj 3039 Jade Toad Hall maximum sub-matrix calculation ♂ Method ②

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.