POJ 1088 skiing
Description
It's not surprising that Michael loves skiing because skiing is really exciting. But in order to get the speed, the slide area must be tilted down, and when you slide to the bottom, you have to go uphill again or wait for the elevator to carry you. Michael wants to know the longest landslide in a region. A region is given by a two-dimensional array. Each number in the array represents the vertex height. The following is an example.
1 2 3 4 516 17 18 19 615 24 25 20 714 23 22 21 813 12 11 10 9
A person can slide from a certain point to one of the four adjacent points up and down, when and only when the height is reduced. In the preceding example, a slide is 24-17-16-1. Of course, 25-24-23-...-3-2-1 is longer. In fact, this is the longest one.
Input
The first line indicates the number of rows in the region R and the number of columns C (1 <= R, C <= 100 ). Below is the R row, each row has a C integer, representing the height h, 0 <= h <= 10000.
Output
The length of the maximum output area.
Sample Input
5 51 2 3 4 516 17 18 19 615 24 25 20 714 23 22 21 813 12 11 10 9
Sample Output
25
Idea: recursive thinking, enumeration of different points for the end, so that the path to the end is the longest, then dp [I] [j] = max (dp [I] [j], d )).
AC code:
# Include
# Include
Using namespace std; int map [105] [105]; int d [105] [105]; int r, c; int dir [4] [2] =, 1, 0,-1, 0,-1}; int dp (int y, int x) {int I; int maxx = 0, s; if (d [y] [x]! = 0) return d [y] [x]; // if the point already has a value, there is no need to recursion for (I = 0; I <4; I ++) {int a = y + dir [I] [0]; int B = x + dir [I] [1]; if (a> = 0 &
= 0 & B
Map [y] [x]) {s = dp (a, B); if (s> maxx) // transfer equation maxx = s ;}}} d [y] [x] = maxx + 1; return d [y] [x];} int main () {int I, j; int maxx =-1; scanf ("% d", & r, & c); for (I = 0; I