UVA10285 Longest Run on a Snowboard

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA10285 Longest Run on a Snowboard相关的知识,希望对你有一定的参考价值。

题解:

记忆化搜索入门题

代码:

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define se second
#define fs first
#define LL long long
#define CLR(x) memset(x,0,sizeof x)
#define MC(x,y) memcpy(x,y,sizeof(x))  
#define SZ(x) ((int)(x).size())
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 
typedef pair<int,int> P;
const double eps=1e-9;
const int maxn=200100;
const int mod=1e9+7;
const int INF=1e9;

int M[110][110];
int dp[110][110];
char name[50];
int r,c;

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int DP(int x,int y)
{
    int &m=dp[x][y];
    if(m) return m;
    m=1;
    for(int i=0;i<4;i++)
    {
        int a=x+dx[i];
        int b=y+dy[i];
        if(a>0&&a<=r&&b>0&&b<=c&&M[a][b]<M[x][y]) m=max(DP(a,b)+1,m);
    }
    return m;
}


int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        memset(dp,0,sizeof(dp));
        scanf("%s %d %d",name,&r,&c);
        for(int i=1;i<=r;i++)
        for(int j=1;j<=c;j++) scanf("%d",&M[i][j]);
        int Max=1;
        for(int i=1;i<=r;i++)
        for(int j=1;j<=c;j++) Max=max(Max,DP(i,j));
        printf("%s: %d\n",name,Max);
    }
    return 0;
}

 

以上是关于UVA10285 Longest Run on a Snowboard的主要内容,如果未能解决你的问题,请参考以下文章

uva 10285 Longest Run on a Snowboard

一道dfs和dp结合的好题 --- Longest Run on a SnowboardUVA-10285

UVA10405 Longest Common SubsequenceLCS+DP

Uva 11151 - Longest Palindrome

UVA10191 Longest Nap排序

UVA 10100 Longest Match