jumpgame 어디가 잘못됐는지 모르겠어요 ㅠ

  • happyer16
    happyer16
    #include <iostream>
    
    using namespace std;
    
    bool findPath = false;
    
    inline int jump(int current, int jump) { return current + jump; }
    
    void find(int* maze, int* check_maze,int current, int size) {
        int move = maze[current];
        cout << "좌표 : (" << current%size << ", " << current / size << ")" << endl;
    
    
            if (move == 0) {
                findPath = true;
                return;
            }
            else{
                int right = jump(current, move);
                int down = jump(current, move * size);
                if (right < (current / size + 1)*size  && !findPath) {
                    if(check_maze[right]!=1)
                        find(maze, check_maze, right, size);
                }
                if (down / size < size  && !findPath) {
                   if(check_maze[down]!=1)
                        find(maze, check_maze, down, size);
                }
                check_maze[current]=1;
    
            }
    
    }
    
    int main() {
        int testCase;
        int size;
    
        cin >> testCase;
        bool* find_result = new bool[testCase];
    
        for (int i = 0; i < testCase; i++) {
            cin >> size;
            int* maze = new int[size*size];
            int* check_maze=new int[size*size];
    
            for (int j = 0; j < size; j++) {
                int m = j*size;
                for (int k = 0; k < size; k++) {
                    cin >> maze[m + k];
                }
            }
    
            find(maze, check_maze, 0, size);
            find_result[i] = findPath;
    
            delete[] maze;
            findPath = false;
        }
    
        for (int i = 0; i < testCase; i++) {
            if (find_result[i]) cout << "YES" << endl;
            else cout << "NO" << endl;
        }
        return 0;
    }
    

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

    jumpgame은 동적계획법을 이용해야 하는 문제인데요 동적계획법은 메모리를 많이 사용해 시간을 단축시키는 기법으로 중복되는 부분문제를 별도의 기억장소에 저장시켜두었다가 계산과정없이 바로 사용하도록 하는 문제입니다.

    크기 50정도의 보드를 만들어서 끝부분만 2로 만들고 테스트를 해보시면 아마 오래걸릴거에요


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