ski
Topic limit
time limit | Memory Limit | Reviews way | Source title |
1000ms | 131072KiB | Standard Comparators | Local |
Topic background
Cheng Cheng first simulation game of the third channel
Title Description
trs like skiing. He came to a ski resort, the ski resort is a rectangle, for simplicity, we use the matrix row r c columns to represent each terrain. In order to get more speed, taxiing route to be downward.
For example, that the rectangular sample, one can slide up and down four points from a point adjacent. For example 24-17-16-1, in fact, 25-24-23 ... 3-2-1 longer, in fact, this is the longest one.
Input Format
Input File
Line 1: two numbers r, c (1 <= r , c <= 100), the row and column matrix.
First 2..r + 1 line: the number of each line c shows the matrix.
Output Format
Output file
only one row: an output integer represents the maximum length may be sliding.
Sample data
Input Sample # 1 | Sample Output # 1 |
---|---|
5 5 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 |
25 |
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #define ll long long; 6 7 using namespace std; 8 9 int n,m; 10 int arr[105][105]; 11 int fx[4][2]={0,1,0,-1,1,0,-1,0}; 12 int dp[105][105]; 13 14 int dfs(int x,int y){ 15 if(dp[x][y]) return dp[x][y]; 16 int maxx=1; 17 for(int i=0;i<4;i++){ 18 int xx=x+fx[i][0]; 19 int yy=y+fx[i][1]; 20 if(xx>=1&&xx<=n&&yy>=1&&yy<=m&&arr[xx][yy]>arr[x][y]){ 21 maxx=max(maxx,dfs(xx,yy)+1); //自底向上的 22 } 23 } 24 dp[x][y]=maxx; //记忆化 25 return maxx; 26 } 27 28 int main(){ 29 ios::sync_with_stdio(false); 30 cin>>n>>m; 31 for(int i=1;i<=n;i++) 32 for(int j=1;j<=m;j++) 33 cin>>arr[i][j]; 34 int res=0; 35 for(int i=1;i<=n;i++) 36 for(int j=1;j<=m;j++){ 37 dp[i][j]=dfs(i,j); 38 res=max(res,dp[i][j]); 39 } 40 cout << res << endl; 41 return 0; 42 }