HDU 1505 City Game-dp-(maximum sub-Matrix Model)

Source: Internet
Author: User

HDU 1505 City Game-dp-(maximum sub-Matrix Model)

 

Analysis: The formula using the largest word matrix times out. Another way of thinking, this question is related to the previous question 1506. First, calculate the maximum height that each element can reach at the bottom of each layer, and then it will be the same as 1506. Here we use dp to store data at the height and area. To calculate the height, use a dual loop, and then each layer is used as the base to find the area. The dual loop plus the outer layer is a triple loop. However, because dp is used to save the intermediate results, this triple loop will not time out. Dp [j] indicates the maximum height that can be reached by column j of the current layer. For status transfer: 1.a[ I] [j] = 'R', dp [j] = 0; 2. otherwise, if a [I-1] [j] = 'F', dp [j] ++ (dp is used here, the data of the front layer is saved, so directly + 1); If a [I-1] [j] = 'R', then dp [j] = 1 ,. For the algorithm for area calculation on each layer, see section 1506.

Code:

 

# Include
 
  
Using namespace std; int t, m, n; int mx, sum; int l [1005], r [1005], dp [1005]; char a [1005] [1005]; int max (int I, int j) {return I> j? I: j;} void fir () // process the first layer {mx = 0; for (int j = 0; j
  
   
0 & dp [I] <= dp [T-1]) t = l [T-1]; l [I] = t;} for (int I = n-2; i> = 0; I --) {int t = I; while (t
   
    
0 & dp [I] <= dp [T-1]) t = l [T-1]; l [I] = t;} for (int I = n-2; i> = 0; I --) {int t = I; while (t
    
     
> T; while (t --) {cin> m> n; for (int I = 0; I
     
      
> A [I] [j]; DP (); cout <
      
       

 

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.