有请路过的DALAO找不同

P1434 [SHOI2002] 滑雪

g1306374356 @ 2021-08-25 16:32:51

RT 以下有两份代码, 一份是本人按照老师的代码抄来的, 一份是把老师的代码复制粘贴下来的,结果评测结果不一样, 请各位大佬一起来找不同(也许是日常眼瞎,反正我是没看出来哪不一样)代码如下:

//WA 30分 
#include<bits/stdc++.h>
using namespace std;

const int N = 310;
int n, m;
int g[N][N];
int f[N][N];

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

int dp(int x, int y)
{
    int &v = f[x][y];
    if(v != -1)return v;

    v = 1;
    for(int i = 0; i < 4; i ++)
    {
        int a = x + dx[i],b = y + dy[i];

        if(a >= 1 && a <= n && b >= 1 && b <= m && g[x][y] > g[a][b])
            v = max(v, dp(a, b) + 1);

        return v;
    }
} 

int main()
{
    scanf("%d%d", &n, &m);

    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= m; j ++)
            scanf("%d", &g[i][j]);

    memset(f, -1, sizeof f);

    int res = 0;
    for(int i = 1; i <= n; i ++)
        for(int j = 1; j <= m; j ++)
            res = max(res, dp(i, j));

    printf("%d\n", res);

    return 0;
}
//AC 100
#include <bits/stdc++.h>

using namespace std;

const int N = 310;

int n, m;
int g[N][N];
int f[N][N];

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

int dp(int x, int y)
{
    int &v = f[x][y];
    if (v != -1) return v;

    v = 1;
    for (int i = 0; i < 4; i ++ )
    {
        int a = x + dx[i], b = y + dy[i];
        if (a >= 1 && a <= n && b >= 1 && b <= m && g[x][y] > g[a][b])
            v = max(v, dp(a, b) + 1);
    }

    return v;
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i ++ )
        for (int j = 1; j <= m; j ++ )
            scanf("%d", &g[i][j]);

    memset(f, -1, sizeof f);

    int res = 0;
    for (int i = 1; i <= n; i ++ )
        for (int j = 1; j <= m; j ++ )
            res = max(res, dp(i, j));

    printf("%d\n", res);

    return 0;
}

另:附评测记录:

前一份代码:30分

后一份代码:100分

希望有能找到不同的dalao告知我。


by 曹操废了 @ 2021-08-25 16:37:51

函数的return位置错了吧

满分代码在for循环后有个return

你的是在循环中return的吧


by 六子轩 @ 2021-08-25 16:37:55

return v写在循环里了!


by 一只大龙猫 @ 2021-08-25 16:41:18

@g1306374356 文本比对器


by g1306374356 @ 2021-08-25 16:46:16

@曹操废了 @lzx1609 @一只大龙猫 谢谢各位, 日常眼瞎


|