题目:https://www.luogu.org/problem/show?pid=1434
搜索不知道怎么样,反正我用记忆化了。
1 #include<cstdio> 2 #include<iostream> 3 #include<cmath> 4 using namespace std; 5 int n,m; 6 int xx[4]={1,0,-1,0}; 7 int yy[4]={0,1,0,-1}; 8 int max1=-99999999; 9 int x1,x2; 10 int a[1300][1300]; 11 int f[105][105]; 12 int dfs(int x,int y) 13 { 14 for(int i=0;i<=3;i++) 15 { 16 if(x+xx[i]>=1&&y+yy[i]>=1&&x+xx[i]<=n&&y+yy[i]<=m) 17 { 18 if(a[x][y]>a[x+xx[i]][y+yy[i]]) 19 { 20 if(f[x+xx[i]][y+yy[i]]!=1) f[x][y]=max(f[x+xx[i]][y+yy[i]]+1,f[x][y]); 21 else f[x][y]=max(dfs(x+xx[i],y+yy[i])+1,f[x][y]); 22 } 23 } 24 } 25 return f[x][y]; 26 } 27 int main() 28 { 29 scanf("%d%d",&n,&m); 30 for(int i=1;i<=n;i++) 31 for(int j=1;j<=m;j++) 32 { 33 scanf("%d",&a[i][j]); 34 f[i][j]=1; 35 } 36 for(int i=1;i<=n;i++) 37 for(int j=1;j<=m;j++) 38 {if(dfs(i,j)>max1) 39 max1=dfs(i,j); 40 } 41 printf("%d",max1); 42 return 0; 43 }
骗分真神奇,暴力出奇迹。