ABOUT ME

Today
Yesterday
Total
  • 백준 - 파이프 옮기기 1 [17070]
    공부/baekjoon 문제 2019. 6. 13. 15:32
    #include <iostream>
    #include <algorithm>
    #include <queue>
    
    using namespace std;
    
    
    class node {
    public:
    	int i;
    	int j;
    	int status;
    	node(int _i, int _j, int _status) {
    		i = _i;
    		j = _j;
    		status = _status;
    	}
    
    	node() {
    		i = 0;
    		j = 0;
    		status = 0;
    	}
    };
    
    
    
    int map[16][16];
    int result;
    queue<node> q;
    void bfs(int n) {
    	q.push(node(0,1,1));
    	node temp;
    	int status;
    	int i;
    	int j;
    	int right, below, diagonal;
    	while (!q.empty()) {
    		temp = q.front();
    		i = temp.i;
    		j = temp.j;
    		status = temp.status;
    		if (i == n - 1 && j == n - 1) {
    			result++;
    		}
    		else {
    			if (j < n - 1)
    				right = map[i][j + 1];
    			if (i < n - 1)
    				below = map[i + 1][j];
    			if (i < n - 1 && j < n - 1)
    				diagonal = map[i + 1][j + 1];
    
    
    			if (status == 1) {
    				if (j < n - 1 && right != 1) {
    					q.push(node(i, j + 1, 1));
    				}
    				if (i < n - 1 && j < n - 1 && diagonal != 1 && right != 1 && below != 1) {
    					q.push(node(i + 1, j + 1, 3));
    				}
    			}
    
    			if (status == 2) {
    				if (i < n - 1 && below != 1) {
    					q.push(node(i + 1, j, 2));
    				}
    				if (i < n - 1 && j < n - 1 && diagonal != 1 && right != 1 && below != 1) {
    					q.push(node(i + 1, j + 1, 3));
    				}
    			}
    			if (status == 3) {
    				if (j < n - 1 && right != 1) {
    					q.push(node(i, j + 1, 1));
    				}
    				if (i < n - 1 && below != 1) {
    					q.push(node(i + 1, j, 2));
    				}
    				if (i < n - 1 && j < n - 1 && diagonal != 1 && right != 1 && below != 1) {
    					q.push(node(i + 1, j + 1, 3));
    				}
    			}
    	
    		}
    		q.pop();
    
    	}
    
    	return;
    }
    
    
    
    
    int main() {
    	int n;
    	cin >> n;
    
    	for (int i = 0; i < n; i++)
    		for (int j = 0; j < n; j++)
    			cin >> map[i][j];
    
    	bfs(n);
    
    	cout << result;
    	return 0;
    }

    '공부 > baekjoon 문제' 카테고리의 다른 글

    댓글

Designed by Tistory.