ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 백준 17070번 C++ 풀이
    백준 2019. 8. 30. 13:55

    https://www.acmicpc.net/problem/17070

    
    //
    //  main.cpp
    //  ps
    //
    //  Created by MOZZET PC on 22/07/2019.
    //  Copyright © 2019 Noondate. All rights reserved.
    //
    
    #include <iostream>
    #include <vector>
    #include <cstring>
    #include <queue>
    #include <map>
    #include <climits>
    #include <algorithm>
    #include <stack>
    
    using namespace std;
    
    int n;
    int buffer[17][17];
    int answer = 0;
    
    bool is_range(int x, int y) {
      return (0 <= x && x < n && 0 <= y && y < n && buffer[x][y] == 0);
    }
    
    bool is_end(int x, int y) {
      return (x == n-1 && y == n-1 );
    }
    void horizontal(int x, int y);
    void vertical(int x, int y);
    void cross_v(int x, int y);
    
    // 가로
    void horizontal(int x, int y) {
    
      if (!(is_range(x, y) && is_range(x, y +1))) {
        return;
      }
      if (is_end(x, y) || is_end(x, y+1)){
        answer++;
        return;
      }
      horizontal(x, y+1);
      cross_v(x, y+1);
    }
    
    // 세로
    
    void vertical(int x, int y) {
    
      if (!(is_range(x, y) && is_range(x+1, y))) {
        return;
      }
      if (is_end(x, y) || is_end(x+1, y)){
        answer++;
        return;
      }
    
      vertical(x+1, y);
      cross_v(x+1, y);
    }
    
    void cross_v(int x, int y) {
      if (!(is_range(x, y) && is_range(x + 1, y +1) && is_range(x, y+1) && is_range(x+1, y))) {
        return;
      }
      if (is_end(x, y) || is_end(x + 1, y+1)){
        answer++;
        return;
      }
    
      horizontal(x+1, y+1);
      vertical(x+1, y+1);
      cross_v(x+1, y+1);
    }
    
    
    
    int main(int argc, const char * argv[]) {
      cin >> n;
    
      for (auto x = 0; x < n; x++) {
        for (auto y = 0; y<n; y++) {
          cin >> buffer[x][y];
        }
      }
    
      horizontal(0, 0);
    
      cout << answer;
    
      return 0;
    }
    

    '백준' 카테고리의 다른 글

    백준 13413번 C++ 풀이  (0) 2019.11.09
    백준 2096번 C++ 풀이  (0) 2019.10.29
    백준 11559번 C++ 코드  (0) 2019.08.29
    백준 2799번 C++ 풀이  (0) 2019.01.04
    백준 2468번 C++ 풀이  (0) 2018.11.25

    댓글 0

Designed by Tistory.