728x90
https://www.acmicpc.net/problem/15684
15684번: 사다리 조작
사다리 게임은 N개의 세로선과 M개의 가로선으로 이루어져 있다. 인접한 세로선 사이에는 가로선을 놓을 수 있는데, 각각의 세로선마다 가로선을 놓을 수 있는 위치의 개수는 H이고, 모든 세로선
www.acmicpc.net
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#include <stdio.h>
int n, m, h, ret;
int map[31][11];
bool check(){
bool ret = true;
for(int i = 1; i <=n; i++){
int pos = i;
for(int j = 0; j <= h; j++){
if(map[j][pos] == 1) { //선이 있음
pos++;
} else if (map[j][pos -1] ==1){
pos--;
}
}
if(pos != i){
return ret = false;
}
}
return ret;
}
void dfs(int count, int y, int x){
if(count >= ret) return ;
if(check()){
ret = count;
return;
}
if(count == 3) return ;
for(int i = y; i <= h; i++){
for(int j = x; j < n; j++){
if(map[i][j] == 0 && map[i][j - 1] == 0 && map[i][j + 1] == 0){ //선을 그을수 있으면
map[i][j] = 1;
dfs(count + 1, i, j);
map[i][j] = 0;
}
}
x = 1;
}
}
int main(){
scanf("%d %d %d", &n, &m, &h);
int a, b;
for (int i = 0; i < m; i++){
scanf("%d %d", &a, &b);
map[a][b] = 1;
}
ret = 4;
dfs(0, 1, 1);
if(ret == 4) ret = -1;
printf("%d\n", ret);
return 0;
}
|
728x90
'Algorithm Study > BOJ with C++' 카테고리의 다른 글
(BAEKJOON) 16243번: 인구 이동 (0) | 2020.07.08 |
---|---|
(BAEKJOON) 15686번: 치킨 배달 (0) | 2020.07.08 |
(BAEKJOON) 15683번: 감시 (0) | 2020.07.08 |
(BAEKJOON) 13460번: 구슬 탈출2 (0) | 2020.07.08 |
(BAEKJOON) 백준 16236번: 아기 상어 (0) | 2020.05.04 |
댓글