Poj 1088: skiing (Classic DP + Memory search)

Source: Internet
Author: User

Skiing
Time limit:1000 ms   Memory limit:65536 K
Total submissions:74996   Accepted:27818

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


You don't have to worry about questions .. 23333


# Include <algorithm> # include <iostream> # include <cstring> # include <cstdio> # include <vector> # include <queue> # include <cmath> using namespace STD; const int M = 105; int n, m; int map [m] [m]; int ans [m] [m]; int DX [] = {1,-1, 0, 0}; int dy [] = {0, 0,-1, 1}; int dp (int x, int y) {int max = 0; if (ANS [x] [Y]> 0) return ans [x] [Y]; for (INT I = 0; I <4; I ++) // Four Directions: {int xx = x + dx [I]; int YY = Y + dy [I]; If (XX> = 1 & XX <= N & YY> = 1 & YY <= m) // boundary {If (Map [x] [Y]> map [XX] [YY]) // valid from high to low if (max <dp (XX, YY) max = dp (XX, YY );}} return ans [x] [Y] = MAX + 1;} int main () {While (scanf ("% d", & N, & M )! = EOF) {memset (MAP, 0, sizeof (MAP); memset (ANS, 0, sizeof (ANS); For (INT I = 1; I <= N; I ++) for (Int J = 1; j <= m; j ++) scanf ("% d", & map [I] [J]); for (INT I = 1; I <= N; I ++) for (Int J = 1; j <= m; j ++) DP (I, j ); for (INT I = 1; I <= N; I ++) for (Int J = 1; j <= m; j ++) if (ANS [1] [1] <ans [I] [J]) ans [1] [1] = ans [I] [J]; printf ("% d \ n", ANS [1] [1]);} return 0 ;}





Poj 1088: skiing (Classic DP + Memory search)

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.