-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17136.cpp
More file actions
117 lines (108 loc) · 1.6 KB
/
17136.cpp
File metadata and controls
117 lines (108 loc) · 1.6 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// 17136. 색종이 붙이기
// 2019.05.22
// 브루트 포스
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int map[11][11];
int ans = 25; // 최대치로 초기화
int blocks[5] = { 5,5,5,5,5 };
bool check(int x, int y, int cnt)
{
for (int i = x; i < x + cnt; i++)
{
for (int j = y; j < y + cnt; j++)
{
if (map[i][j] == 0)
{
return false;
}
}
}
return true;
}
void go(int x, int y, int cnt)
{
int flag = 0;
// x,0부터 처음으로 0이 아닌 수가 나오는 지점을 찾음
for (int i = x; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
if (map[i][j] == 1)
{
x = i;
y = j;
flag = 1;
break;
}
}
if (flag)
{
break;
}
}
if (flag == 0)
{
ans = min(ans, cnt);
return;
}
for (int i = 1; i <= 5; i++)
{
// 5개를 다썼다면 무시
if (blocks[i - 1] == 0)
{
continue;
}
// 덮을수 없는 점이라면 종료
if (check(x, y, i) == false)
{
return;
}
// 덮을 수 있다면 덮는 크기의 색종이 숫자 감소
else
{
blocks[i - 1]--;
}
// 색종이를 덮음
for (int j = x; j < x + i; j++)
{
for (int k = y; k < y + i; k++)
{
map[j][k] = 0;
}
}
go(x, y, cnt + 1);
// 감소한 숫자 복구
blocks[i - 1]++;
// 덮은거 복구
for (int j = x; j < x + i; j++)
{
for (int k = y; k < y + i; k++)
{
map[j][k] = 1;
}
}
}
}
int main()
{
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
cin >> map[i][j];
}
}
go(0, 0, 0);
if (ans == 25)
{
cout << -1 << endl;
}
else
{
cout << ans << endl;
}
return 0;
}