标签:
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
#include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> using namespace std; const int maxn = 105; int r,c,ans; int h[maxn][maxn],f[maxn][maxn]; int dx[4] = {-1,0,1,0}; int dy[4] = {0,-1,0,1}; bool jud(int i,int j){ if(i < 1 || i > r || j < 1 || j > c) return false; return true; } int dp(int i,int j){ if(f[i][j]) return f[i][j]; f[i][j] = 1; int y,x; for(int t = 0;t < 4;t++){ y = i + dy[t]; x = j + dx[t]; if(jud(y,x) && h[i][j] > h[y][x]) f[i][j] = max(f[i][j],1 + dp(y,x)); } return f[i][j]; } int main(){ cin>>r>>c; for(int i = 1;i <= r;i++){ for(int j = 1;j <= c;j++){ cin>>h[i][j]; } } for(int i = 1;i <= r;i++){ for(int j = 1;j <= c;j++){ ans = max(ans,dp(i,j)); } } cout<<ans; return 0; }
标签:
原文地址:http://www.cnblogs.com/hyfer/p/5754620.html