POJ 1088: Skiing (classic dp+ memory Search)

Source: Internet
Author: User

Ski

Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 74996 Accepted: 27818

It's not surprising that Description Michael likes to ski, because skiing is really exciting. But to get the speed, the slippery area must tilt downward, and when you slide to the bottom, you have to go up the slope again or wait for the lift to load you. Michael wants to know the longest bottom landslide in a region. The area is given by a two-dimensional array. Each digit of the array represents the height of the point. Here is an example

1  2  3  4 5,

6

7, 8 and 13, 12 11 10

One can slide from one point to the next four points adjacent to one another, when and only if the height decreases. In the example above, a sliding landslide is 24-17-16-1. Of course 25-24-23-...-3-2-1 longer. In fact, this is the longest one.

The first line of input inputs represents the number of rows R and the number of columns C (1 <= r,c <= 100) of the range. The following are the r lines, each with a C integer representing a height of h,0<=h<=10000.

The length of the maximum area of output outputs.

Sample Input

5 5
1 2 3 4 5, 6 7, 8 (13) 12 11 10 9

Sample Output

25


I don't have to worry about the problem. 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])
        From high to low legal if (Max < DP (xx, yy)) max = DP (xx, YY);
}} return Ans[x][y] = max + 1;
        } int main () {while (scanf ("%d%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;
 }





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.