1 #define _CRT_SECURE_NO_WARNINGS 2 #include <stdio.h> 3 #include <math.h> 4 #include <algorithm> 5 #include <stdlib.h> 6 #include <vector> 7 #include <map> 8 #include <queue> 9 #include <string> 10 #include <iostream> 11 #include <ctype.h> 12 #include <string.h> 13 #include <set> 14 #include <stack> 15 #include<functional> 16 using namespace std; 17 #define size 105 18 #define maxn 1<<30 19 int dp[size][size];//以i,j为结尾的线段所滑行的最大距离 20 int a[size][size]; 21 int row, col; 22 int go[4][2] = { 1, 0, 0, 1, -1, 0, 0, -1 }; 23 int solve(int x, int y){//表示以x,y结尾的点所滑翔的最大距离,从最低点往上收敛 24 if (dp[x][y] != -1) return dp[x][y]; 25 int ret = 1; 26 for (int i = 0; i < 4; i++){ 27 int tx = x + go[i][0]; 28 int ty = y + go[i][1]; 29 if (tx < 1 || ty<1 || tx>row || ty>col) continue; 30 if(a[x][y]<a[tx][ty]) ret = max(ret, solve(tx, ty)+1); 31 } 32 dp[x][y] = ret; 33 return ret; 34 } 35 int main(){ 36 cin >> row >> col; 37 for (int i = 1; i <= row; i++) 38 for (int j = 1; j <= col; j++){ 39 dp[i][j] = -1; 40 cin >> a[i][j]; 41 } 42 int ans = 1; 43 for (int i = 1; i <= row; i++) 44 for (int j = 1; j <= col; j++) 45 ans = max(ans, solve( i, j)); 46 cout << ans << endl; 47 system("pause"); 48 return 0; 49 }
原文地址:https://www.cnblogs.com/MapReduce/p/8367263.html
时间: 2024-10-03 10:21:02