[c艹] dfs+记忆化 80' 求助大佬

P1434 [SHOI2002] 滑雪

D_guard @ 2022-06-27 10:49:04

rt,#2 #6 WA

提交记录见此

蒟蒻代码见下或见提交记录:

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int r, c, h[102][102], l[102][102], ans;
int trn[4][2] = {-1,0,0,-1,1,0,0,1};

int dfs(int x, int y){
    if(l[x][y]) return l[x][y];
    l[x][y] = 1;
    for(int i=0; i<4; ++i){
        int x2 = x+trn[i][0],
            y2 = y+trn[i][1];
        if(x2>0 && x2<=r && y2>0 && y2<=c && h[x2][y2]<h[x][y])
            l[x][y] = max(l[x][y], dfs(x2, y2)+1);
    }
    return l[x][y];
}

int main(){
    scanf("%d%d", &r,&c);
    for(int i=1; i<=r; ++i)
        for(int j=1; j<=r; ++j)
            scanf("%d", &h[i][j]);
    for(int i=1; i<=r; ++i)
        for(int j=1; j<=c; ++j)
            ans = max(ans, dfs(i, j));
    printf("%d", ans);
    return 0;
}

望大佬解惑,万分感谢!


by IamYoung2021 @ 2022-06-28 19:49:34

问题似乎不大 输入有问题

for(int i=1; i<=r; ++i)
    for(int j=1; j<=r; ++j)
    scanf("%d", &h[i][j]);

变为

for(int i=1; i<=r; ++i)
    for(int j=1; j<=c; ++j)
    scanf("%d", &h[i][j]);

by D_guard @ 2022-07-01 14:47:18

@IamYoung_chensiming 感谢大佬,已A!

(输入写错还能80'也挺离谱的)


by 许多 @ 2022-07-06 15:32:21

《c艹》


|