Identify all paths at each point, and find the maximum path from this point as the starting point
Figure out the maximum path of each point and then find the maximum value, output maximum
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#define N 101
using namespace Std;
int hang, Lie;
int dir[4][2]= {{ -1,0},{0,-1},{1,0},{0,1}};//defines four directions
int len[n][n],map1[n][n];
int dp (int i,int j)
{
if (len[i][j]!=0) return len[i][j];//the length of the current slope
int s,max1=0;
for (int t=0; t<4; t++)
{
int sx=i+dir[t][0];
int sy=j+dir[t][1];
if (Sx>=0&&sx{
S=DP (Sx,sy);//Calculates the slope of a path starting at this position
if (S>MAX1) max1=s;//find the largest
}
}
len[i][j]=max1+1;
return max1+1;
}
int main ()
{
while (~SCANF ("%d%d", &hang,&lie))
{
memset (len,0,sizeof (len));
for (int i=0; ifor (int j=0; j<lie; j + +)
scanf ("%d", &map1[i][j]);
int max2=-1;
for (int i=0; ifor (int j=0; j<lie; j + +)
{
LEN[I][J]=DP (I,J);//calculates the maximum length at any point as the starting point
if (LEN[I][J]>MAX2) max2=len[i][j];//find the maximum length again
}
printf ("%d\n", MAX2);
}
}
Skiing (search) (DP) (greedy)