第四个点答案是1我输出的是0,求助

P1434 [SHOI2002] 滑雪

alxdsptr @ 2023-08-08 02:51:22

代码如下,想不出来有什么原因会输出0

#include <iostream>
#include <algorithm>
#include <cmath>
#define MAX_LEN 102
using namespace std;
struct point{
    int height;
    int x, y;
}p[10000];
int dp[MAX_LEN][MAX_LEN], go[4][2] = {{0,1}, {0, -1}, {1, 0}, {-1, 0}};
int hill[MAX_LEN][MAX_LEN];
bool cmp(point a, point b){
    return a.height < b.height;
}
int ans;
void compute(point a){
    int x, y;
    for(int i = 0; i < 4; i++){
        x = a.x + go[i][0], y = a.y + go[i][1];
        if(hill[x][y] < a.height){
            dp[a.x][a.y] = max(dp[a.x][a.y], dp[x][y] + 1);
        }
    }
    if(dp[a.x][a.y] > ans)
        ans = dp[a.x][a.y];
}

int main(){
    int r, c, tmp = 0;
    int i, j;
    cin >> r >> c;
    for(i = 1; i <= r; i++){
        for(j = 1; j <= c; j++){
            cin >> p[tmp].height;
            hill[i][j] = p[tmp].height;
            p[tmp].x = i;
            p[tmp].y = j;
            tmp++;
            dp[i][j] = 1;
        }
    }
    for(i = 0, j = 0; j <= c + 1; j++){
        hill[i][j] = 2147483647;
    }for(i = r + 1, j = 0; j <= c + 1; j++){
        hill[i][j] = 2147483647;
    }for(j = 0, i = 0; i <= r + 1; i++){
        hill[i][j] = 2147483647;
    }for(j = c + 1, i = 0; i <= r + 1; i++){
        hill[i][j] = 2147483647;
    }
    sort(p, p + tmp, cmp);
    for(i = 1; i < tmp; i++){
        compute(p[i]);
    }
    cout << ans;
}

by _8008008 @ 2023-08-27 15:43:44

n=1&m=1时ans=1,特判


|