Skiing (search) (DP) (greedy)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.