蒟蒻求助 70分

P1434 [SHOI2002] 滑雪

YurneroZ @ 2019-04-03 19:47:01

include <stdio.h>

include <algorithm>

using namespace std; const int e=105; int num[e][e]; int step[e][e]; int R,C; int maxx=0; int dir[4][2]={1,0,-1,0,0,1,0,-1}; int dfs(int x,int y) { if(step[x][y]) return step[x][y]; int sum=1; for(int i=0;i<4;i++) { int now_x=x+dir[i][0]; int now_y=y+dir[i][1]; if(now_x>=1&&now_x<=C&&now_y>=1&&now_y<=R) { if(num[now_x][now_y]<num[x][y]) sum=max(sum,dfs(now_x,now_y)+1); } } return step[x][y]=max(step[x][y],sum); } int main(int argc, char const *argv[]) { scanf("%d%d",&R,&C); for(int i=1;i<=R;i++) for(int j=1;j<=C;j++) scanf("%d",&num[i][j]); for(int i=1;i<=R;i++) for(int j=1;j<=C;j++) maxx=max(maxx,dfs(i,j)); printf("%d\n",maxx); return 0; }


by YurneroZ @ 2019-04-03 19:47:39

#include <stdio.h>
#include <algorithm>
using namespace std;
const int e=105;
int num[e][e];
int step[e][e];
int R,C;
int maxx=0;
int dir[4][2]={1,0,-1,0,0,1,0,-1};
int dfs(int x,int y)
{
    if(step[x][y])
        return step[x][y];
    int sum=1;
    for(int i=0;i<4;i++)
    {
        int now_x=x+dir[i][0];
        int now_y=y+dir[i][1];
        if(now_x>=1&&now_x<=C&&now_y>=1&&now_y<=R)
        {
            if(num[now_x][now_y]<num[x][y])
            sum=max(sum,dfs(now_x,now_y)+1);
        }
    }
    return step[x][y]=max(step[x][y],sum);
}
int main(int argc, char const *argv[])
{
    scanf("%d%d",&R,&C);
    for(int i=1;i<=R;i++)
        for(int j=1;j<=C;j++)
            scanf("%d",&num[i][j]);
    for(int i=1;i<=R;i++)
        for(int j=1;j<=C;j++)
            maxx=max(maxx,dfs(i,j));
    printf("%d\n",maxx);
    return 0;
}

by YurneroZ @ 2019-04-03 19:51:50

没人吗

QAQ


by _H1kar1 @ 2019-07-12 22:20:19

同70


|