JUMPGAME 오답 도움 부탁드립니다.

  • tnehtanf
    tnehtanf

    문제 링크 : JUMPGAME

    디버깅으로 값 찍어가며 봐도

    몇 번을 시도해봐도

    오답의 원인을 알 수가 없네요 ㅠㅠ

    도움 부탁드립니다!!

    import java.util.Scanner;

    public class Main
    {
    private static String Answer;
    private static int T;
    private static int N;
    private static int[][] B;
    private static int[][] C;

    private static int jump(int y, int x)
    {
        if( y >= N || x >= N )
            return 0;
    
        if( C[y][x] != -1 )
            return C[y][x];
    
        int jumpSize = B[y][x];
    
        return C[y][x] = jump(y+jumpSize, x) + jump(y, x+jumpSize);
    }
    
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
    
        T = sc.nextInt();
    
        for( int testcase = 0 ; testcase < T ; testcase++ )
        {
            N = sc.nextInt();
    
            B = new int[N][N];
            C = new int[N][N];
    
            for( int i = 0 ; i < N ; i++ )
            {
                for( int j = 0 ; j < N ; j++ )
                {
                    B[i][j] = sc.nextInt();
                    C[i][j] = -1;
                }
            }
    
            C[N-1][N-1] = 1;
    
            if( jump(0, 0) > 0 )
                Answer = "YES";
            else
                Answer = "NO";
    
            System.out.println(Answer);
        }
    }

    }


    8년 전
1개의 댓글이 있습니다.
  • JongMan
    JongMan

    덧셈을 하셔서 그렇습니다.입력이 커질 경우 int 오버플로우가 일어납니다.


    8년 전 link
  • 정회원 권한이 있어야 커멘트를 다실 수 있습니다. 정회원이 되시려면 온라인 저지에서 5문제 이상을 푸시고, 가입 후 7일 이상이 지나셔야 합니다. 현재 문제를 푸셨습니다.