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 <