滑雪
记忆化搜索的简单模版题!
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 int r,c; 6 int s[100][105]; 7 int sign[100][105]; 8 int f[4][2]={{-1,0},{1,0},{0,-1},{0,1}}; 9 int D(int i,int j) 10 { 11 int k; 12 int max; 13 max=0; 14 int x,y; 15 if(sign[i][j]>0)return sign[i][j]; 16 for(k=0;k<4;k++) 17 { 18 x=i+f[k][0]; 19 y=j+f[k][1]; 20 if(x<0||x>=r||y<0||y>=c)continue; 21 if(s[i][j]>s[x][y]) 22 { 23 if(max<D(x,y)) 24 max=D(x,y); 25 } 26 } 27 return sign[i][j]=max+1; 28 } 29 int main() 30 { 31 int i,j; 32 scanf("%d%d",&r,&c); 33 for(i=0;i<r;i++) 34 { 35 for(j=0;j<c;j++) 36 { 37 scanf("%d",&s[i][j]); 38 sign[i][j]=0; 39 } 40 } 41 int max; 42 max=0; 43 for(i=0;i<r;i++) 44 { 45 for(j=0;j<c;j++) 46 { 47 D(i,j); 48 if(max<D(i,j)) 49 max=D(i,j); 50 } 51 } 52 printf("%d\n",max); 53 return 0; 54 }