Nyoj question 10 skiing -- Nanyang OJ

Source: Internet
Author: User
Title information is as follows: skiing time limit: 3000 MS | memory limit: 65535 kb difficulty: 5
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 5

16 17 18 19 6

15 24 25 20 7

14 23 22 21 8

13 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 row indicates the number of test data sets. The second row 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.
The following is the next group of data;
Output
The length of the maximum output area.
Sample Input
15 51 2 3 4 516 17 18 19 615 24 25 20 714 23 22 21 813 12 11 10 9
Sample output
25



The source code is as follows:

#include<stdio.h>int N,HIGH,WIDTH,Max=0;int a[101][101];void skiing(int m,int n,int t){if (m-1 >=0){if (a[m-1][n] < a[m][n]) skiing(m-1,n,t+1);}if (m+1 < HIGH){if (a[m+1][n] < a[m][n]) skiing(m+1,n,t+1);}if (n-1 >= 0){if (a[m][n-1] < a[m][n]) skiing(m,n-1,t+1);}if (n+1 < WIDTH){if (a[m][n+1] < a[m][n]) skiing(m,n+1,t+1);}if (t > Max) Max = t;}int main(){int i,j;scanf("%d",&N);while(N--){Max = 0;scanf("%d%d",&HIGH,&WIDTH);for (i=0; i < HIGH;i++)for (j=0; j < WIDTH; j++)scanf("%d",&a[i][j]);for (i=0; i < HIGH;i++)for (j=0; j < WIDTH; j++)skiing(i,j,1);printf("%d\n",Max);}return 0;}



Nyoj question 10 skiing -- Nanyang OJ

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.