代码:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 typedef long long ll; 6 #define mem(a) memset(a,0,sizeof(a)) 7 #define mp(x,y) make_pair(x,y) 8 const int INF = 0x3f3f3f3f; 9 const ll INFLL = 0x3f3f3f3f3f3f3f3fLL; 10 inline ll read(){ 11 ll x=0,f=1;char ch=getchar(); 12 while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} 13 while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} 14 return x*f; 15 } 16 ////////////////////////////////////////////////////////////////////////// 17 const int maxn = 100+10; 18 19 int n,m,mp[maxn][maxn],dp[maxn][maxn]; 20 int dx[4] = {0,0,1,-1}; 21 int dy[4] = {1,-1,0,0}; 22 23 int dfs(int x,int y){ 24 if(dp[x][y]) return dp[x][y]; 25 for(int i=0; i<4; i++){ 26 int tx=x+dx[i],ty=y+dy[i]; 27 if(tx<1 || tx>n || ty<1 || ty>m || mp[x][y]<=mp[tx][ty]) continue; 28 int tmp = dfs(tx,ty); 29 if(tmp >= dp[x][y]){ 30 dp[x][y] = tmp+1; 31 } 32 } 33 return dp[x][y]; 34 } 35 36 int main(){ 37 n=read(),m=read(); 38 for(int i=1; i<=n; i++) 39 for(int j=1; j<=m; j++) 40 mp[i][j] = read(); 41 42 int ans = 0; 43 mem(dp); 44 for(int i=1; i<=n; i++) 45 for(int j=1; j<=m; j++){ 46 int t = dfs(i,j); 47 if(ans < t) 48 ans = t; 49 } 50 51 cout << ans+1 << endl; 52 return 0; 53 }