Topic: Skiing. Give a two-dimensional array to find the length of the longest continuous descent sequence.
Title Analysis: Defines the length of the longest continuous descent sequence that DP (I,J) represents at the end of A[i][j], then DP (I,J) =max (DP (I-1,J), DP (I+1,J), DP (I,J-1), DP (I,J+1)), Repeat this DP process to update the DP array 100 times (I have done a test specifically, the number of updates in 42 times and above can be AC).
The code is as follows:
# include<iostream># include<cstdio># include<string># include<cstring># include< Algorithm>using namespace Std;int a[105][105],dp[105][105];int n,m;string p;int d[4][2]={{-1,0},{1,0},{0,1},{0,-1 }};bool judge (int x,int y) {return x>=0&&x<n&&y>=0&&y<m;} int solve () {for (Int. i=0;i<n;++i) for (int j=0;j<m;++j) dp[i][j]=1; for (int k=0;k<42;++k) {for (int x=0;x<n;++x) {for (int. y=0;y<m;++y) {for (int) {I=0;i <4;++i) {int nx=x+d[i][0],ny=y+d[i][1]; if (judge (Nx,ny) &&a[x][y]>a[nx][ny]&&dp[x][y]+1>dp[nx][ny]) dp[nx][ny]=dp[x][y ]+1; }}}} int ans=0; for (int. i=0;i<n;++i) for (int j=0;j<m;++j) Ans=max (Ans,dp[i][j]); return ans;} int main () {int T; scanf ("%d", &t); while (t--) {cin>>p; scanf ("%d%d", &n,&m); for (int i=0;i<n;++i) for (int j=0;j<m;++j) scanf ("%d", &a[i][j]); cout<<p<< ":" <<solve () <<endl; } return 0;}
UVA-10285 longest Run on a Snowboard (recursive)