递推求法,最后一个RE了,求大神打救

P1434 [SHOI2002] 滑雪

SakuraBoy @ 2018-10-12 09:40:52

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    static int[][] input;
    static int[][] answer;
    static int[] x_c = {0, 0, 1, -1};
    static int[] y_c = {-1, 1, 0, 0};
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] first = scanner.nextLine().split(" ");
        int R = Integer.valueOf(first[0]);
        int C = Integer.valueOf(first[1]);
        input = new int[R + 3][C + 3];
        answer = new int[R + 3][C + 3];
        int[][] JIA = new int[R + 3][C + 3];
        Point[] points = new Point[R * C];
        int h = 0;
        for (int i = 1; i <= R; i++) {
            for (int j = 1; j <= C; j++) {
                input[i][j] = scanner.nextInt();
                answer[i][j] = 1;
                points[h] = new Point(input[i][j], i , j);
                h++;
            }
        }

        Arrays.sort(points, new Comparator<Point>() {
            @Override
            public int compare(Point o1, Point o2) {
                if (o1.num > o2.num)
                {
                    return 1;
                }
                return -1;
            }
        });
        int max = 1;
        for (int i = 0; i < h; i++) {
            int x = points[i].x, y = points[i].y, num = points[i].num;
            for (int j = 0; j < 4; j++) {
                int x1 = x + x_c[j];
                int y1 = y_c[j] + y;
                if (input[x1][y1] > num)
                {
                    if (JIA[x1][y1] < answer[x][y]) {
                        answer[x1][y1] = answer[x1][y1] - JIA[x1][y1] + answer[x][y];
                        JIA[x1][y1] = answer[x][y];
                    }
                    if (answer[x1][y1] >= max)
                    {
                        max = answer[x1][y1];
                    }
                }
            }
        }
        System.out.print(max);
    }
    static class Point
    {
        int num;
        int x;
        int y;

        public Point(int num, int x, int y) {
            this.num = num;
            this.x = x;
            this.y = y;
        }
    }
}

by RiverFun @ 2018-10-12 10:39:33

@SakuraBoy

%%% Java dalao


by Frostmourne✡凛 @ 2018-10-12 10:44:36

惊现JAVA (吐血)

并不会QAQ,C++党


by kl膜法59改 @ 2018-10-12 14:31:45

惊现java


by SakuraBoy @ 2018-10-28 20:05:35

额,表示渣渣一枚


|