-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path연구소.py
63 lines (51 loc) · 1.38 KB
/
연구소.py
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
#연구소
#3개 설치하는 모든 겨우의 수를 다 계산
n,m = map(int,input().split())
data = []
temp = [[0] * m for _ in range(n)]
for _ in range(n):
data.append(list(map(int,input().split())))
dx = [-1,0,1,0]
dy = [0,1,0,-1]
result = 0
#바이러스 퍼지게 만들기
def virus(x,y):
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if nx >=0 and nx <n and ny >=0 and ny <m:
#바이러스 퍼질 수 있는 경우
if temp[nx][ny] == 0:
temp[nx][ny] = 2
# 그 위치에서 다시 재귀적 실행
virus(nx,ny)
def get_score():
score = 0
for i in range(n):
for j in range(m):
if temp[i][j] == 0:
score += 1
return score
def dfs(count):
global result
if count == 3:
for i in range(n):
for j in range(m):
temp[i][j] = data[i][j]
for i in range(n):
for j in range(m):
if temp[i][j] == 2:
virus(i,j)
# 안전 영역의 최댓값 계
result = max(result,get_score())
return
for i in range(n):
for j in range(m):
if data[i][j] == 0:
data[i][j] = 1
count+=1
dfs(count)
data[i][j] = 0
count -=1
dfs(0)
print(result)