Ski
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 92384 |
|
Accepted: 34948 |
Description
It's not surprising that 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 516 17 18 19 615 24 25 20 714 23 22 21 813 12 11 10 9
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.
Input
The first line of input represents the number of rows in the range R and the number of columns C (1 <= r,c <= 100). The following are the r lines, each with a C integer representing a height of h,0<=h<=10000.
Output
The length of the longest region of the output.
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
Title Link: POJ 1088
Do the first memory of the topic of search, each time the best development results recorded and sent back, very good understanding of
Code:
#include <stdio.h> #include <iostream> #include <algorithm> #include <cstdlib> #include < sstream> #include <cstring> #include <bitset> #include <string> #include <deque> #include <stack> #include <cmath> #include <queue> #include <set> #include <map>using namespace std ; #define INF 0x3f3f3f3f#define CLR (x, y) memset (x,y,sizeof) #define LC (x) (x<<1) #define RC (x) ((x<<1) +1) # Define MID (x, y) ((x+y) >>1) typedef pair<int,int> PII;TYPEDEF Long Long ll;const double Pi=acos ( -1.0); const int n=110;int pos[n][n],direct[4][2]={{0,1},{0,-1},{1,0},{-1,0}};int dp[n][n];int n,m;int dfs (int x,int y) {if (dp[x][y ]) return dp[x][y]; else {int maxm=0; for (int i=0; i<4; ++i) {int xx=x+direct[i][0]; int yy=y+direct[i][1]; if (Xx>=0&&xx<n&&yy>=0&&yy<m&&pos[xx][yy]<pos[x][y]) Maxm=max <int> (MAXm,dfs (XX,YY)); } return dp[x][y]=maxm+1; }}int Main (void) {int i,j; while (~SCANF ("%d%d", &n,&m)) {CLR (dp,0); for (i=0; i<n; ++i) for (j=0; j<m; ++j) scanf ("%d", &pos[i][j]); For (i=0, i<n; ++i) for (j=0; j<m; ++j) DFS (I,J); int Ans=1; For (i=0, i<n; ++i) for (j=0; j<m; ++j) if (Dp[i][j]>ans) ans=dp[i][j ]; printf ("%d\n", ans); } return 0;}
POJ 1088 Ski (memory search)