1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| #include<bits/stdc++.h> #define scan(x) scanf("%lld",&x) #define f(i,a,b) for(int i=a;i<=b;i++) using namespace std; typedef long long LL; const LL N=186; LL dp[N][N],data[N][N],r,c,maxn; LL dyp(LL i,LL j) { if(dp[i][j]!=-1) return dp[i][j]; LL a[4]= {1,1,1,1}; if(i-1>0&&data[i-1][j]<data[i][j]) { a[0]+=dyp(i-1,j); } if(i+1<=r&&data[i+1][j]<data[i][j]) { a[1]+=dyp(i+1,j); } if(j-1>0&&data[i][j-1]<data[i][j]) { a[2]+=dyp(i,j-1); } if(j+1<=c&&data[i][j+1]<data[i][j]) { a[3]+=dyp(i,j+1); } sort(a,a+4); dp[i][j]=a[3]; return a[3]; }
int main() { scan(r); scan(c); f(i,1,r) { f(j,1,c) { scan(data[i][j]); dp[i][j]=-1; } } f(i,1,r) { f(j,1,c) { maxn=maxn<dyp(i,j)?dyp(i,j):maxn; } }
printf("%lld",maxn); return 0; }
|