Skiing
Time Limit:1000 MS |
|
Memory Limit:65536 K |
Total Submissions:68005 |
|
Accepted:25017 |
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
Code:
I am modifying the conditions and understanding the meaning of the question. I can't forgive myself ....
The longest area length of each vertex exists at this point, and can be directly used at this point next time, saving time.
# Include "string. h "# include" stdio. h "int m, n; int a [110] [110]; int record [110] [110]; int slide (int I, int j) {int max = 0, temp; if (I> m | j> n | I <1 | j <1) return 0; if (record [I] [j]) return record [I] [j]; if (a [I + 1] [j] <a [I] [j]) {temp = slide (I + 1, j); if (temp> max) max = temp;} if (a [I-1] [j] <a [I] [j]) {temp = slide (I-1, j); if (temp> max) max = temp;} if (a [I] [j + 1] <a [I] [j]) {temp = slide (I, j + 1); if (temp> max) max = temp;} if (a [I] [J-1] <A [I] [j]) {temp = slide (I, J-1); if (temp> max) max = temp ;} return record [I] [j] = max + 1; // 1 is added with the vertex itself, and the length of the adjacent vertex is 1} int main () {int I, j, max, temp; while (scanf ("% d", & m, & n )! = EOF) {memset (a, 0, sizeof (a); memset (record, 0, sizeof (record); for (I = 1; I <= m; I ++) for (j = 1; j <= n; j ++) scanf ("% d", & a [I] [j]); max = 0; for (I = 1; I <= m; I ++) // calculate the taxi distance of m * n points {for (j = 1; j <= n; j ++) {temp = slide (I, j); if (temp> max) max = temp ;}} printf ("% d \ n", max );} return 0 ;}