-
음료수 얼려먹기코테 대비 python/백준 2022. 2. 15. 10:06
출처: 이코테
DFS 문제인데 어렵다..
30분지나서 답지 참고함;
언제나 보고나면 쉬운것을.. ㅋㅋ
n,m = map(int,input().split())
graph = []
for i in range(n):graph.append(list(map(int,input())))
def dfs(x,y):if x <=-1 or x>=n or y<= -1 or y>=m:return False
if graph[x][y] ==0:graph[x][y]=1dfs(x-1,y)dfs(x,y-1)dfs(x+1,y)dfs(x,y+1)return Truereturn Falseresult = 0for i in range(n):for j in range(m):if dfs(i,j)==True:result +=1
print(result)'코테 대비 python > 백준' 카테고리의 다른 글
성적이 낮은 순서로 학생 출력하기 (0) 2022.02.16 위에서 아래로 (0) 2022.02.16 미로 탈출 (0) 2022.02.15 시간 세기 (0) 2022.02.14 별그리기 (0) 2022.02.13