Test instructions
The n*m matrix that is the length of the longest descending sequence in the matrix.
Analysis:
Dp[i][j] represents the longest descent sequence starting with I,j and then remembers the search.
#include <map>#include<Set>#include<list>#include<cmath>#include<queue>#include<stack>#include<cstdio>#include<vector>#include<string>#include<cctype>#include<complex>#include<cassert>#include<utility>#include<cstring>#include<cstdlib>#include<iostream>#include<algorithm>using namespaceStd;typedef pair<int,int>Pii;typedefLong Longll;#defineLson l,m,rt<<1#definePi ACOs (-1.0)#defineRson m+1,r,rt<<11#defineAll 1,n,1#defineRead Freopen ("In.txt", "R", stdin)Constll infll =0x3f3f3f3f3f3f3f3fll;Const intinf=0x7ffffff;Const intMoD =1000000007;intdp[ the][ the],mapc[ the][ the];intn,m;intdir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};intDfsintXinty) { intf=0; if(dp[x][y]!=-1)returnDp[x][y]; inttmp=-1; for(intI=0;i<4;++i) { intxx=x+dir[i][0]; intyy=y+dir[i][1]; if(xx>=0&&xx<n&&yy>=0&&yy<m&&mapc[xx][yy]<Mapc[x][y]) {tmp=max (Tmp,dfs (XX,YY) +1); F=1; } } if(!f) tmp=1; returndp[x][y]=tmp;}intMain () {strings; intT; scanf ("%d",&t); while(t--) {cin>>s; scanf ("%d%d",&n,&m); for(intI=0; i<n;++i) for(intj=0; j<m;++j) scanf ("%d",&Mapc[i][j]); Memset (DP,-1,sizeof(DP)); intmaxn=-1; for(intI=0; i<n;++i) for(intj=0; j<m;++j) Maxn=Max (Maxn,dfs (i,j)); cout<<s<<": "; printf ("%d\n", MAXN); }return 0;}
Longest Run on a Snowboard