Jumpgame 관련 질문입니다.

  • bjkim07
    bjkim07

    http://algospot.com/judge/problem/read/JUMPGAME
    문제를 풀고 있는데 자꾸 오답이라고 뜨네요!
    예로 준 input과 output은 일치하는데 뭔가 잘못된 부분이 있나봅니다.
    그렇게 어렵지 않은 알고리즘 같은데 해결하지 못하니 너무 답답합니다. ㅠ.ㅠ
    도움을 좀 주십시오 고수님들!!! 엉엉~

    import java.io.*;

    public class Main {
    private int n_case;
    private int[][] p_int;
    private int[][] memo;
    private boolean[] res;

    public static void main(String[] args) {
        Main test = new Main();
        test.in();
        test.out();
    }
    
    public void in() {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            this.n_case = Integer.parseInt (br.readLine().split(" ")[0]);
            this.res = new boolean[this.n_case];
            for (int i=0; i<this.n_case; i++) {
                int s = Integer.parseInt (br.readLine().split(" ")[0]);
                this.p_int = new int[s][s];
                this.memo = new int[s][s];
                for (int j=0; j<s; j++) {
                    String[] helper = new String[s];
                    helper = br.readLine().split(" ");
                    for (int k=0; k<s; k++) {
                        this.p_int[j][k] = Integer.parseInt(helper[k]);
                    }
                }
                this.res[i] = jump(0,0);
            }
        } catch (Exception ex) {}
    }
    
    public void out() {
        for (int i=0;i<this.res.length;i++) {
            if (this.res[i]) {
                System.out.println ("Yes");
            } else {
                System.out.println ("No");
            }
        }
    }
    
    public boolean jump (int y, int x) {
        int l = this.p_int[0].length;
        if (y >= l || x >= l ) {
            return false;
        } 
        if ( (x == (l-1)) && (y == (l-1)) ) {
            return true;
        } 
        if (this.memo[y][x]== 1) {
            return true;
        } 
        if (this.memo[y][x]== -1) {
            return false;
        }
    
        boolean ret;
        int jumpsize = this.p_int[y][x];
        ret = jump (y, x + jumpsize) || jump (y + jumpsize, x);
        if (ret) {
            this.memo[y][x] = 1;
        } else {
            this.memo[y][x] = -1;
        }
        return ret;
    }

    }


    10년 전
4개의 댓글이 있습니다.
  • Kureyo
    Kureyo

    일단..YES NO는 전부 대문자여야합니다


    10년 전 link
  • bjkim07
    bjkim07

    !!!! 감사합니다. 바꿔서 해보겠습니다.


    10년 전 link
  • bjkim07
    bjkim07

    허허허 쿠레요님 너무 감사합니다!!!! 문제는 대문자였군요!!!
    엉엉~


    10년 전 link
  • Kureyo
    Kureyo

    :D


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