https://programmers.co.kr/learn/courses/30/lessons/68936
백준 1780 종이의 개수 와 동일한 분할 정복 문제
def solution(arr):
import sys
sys.setrecursionlimit(10 ** 6)
data = [0, 0]
def divide_arr(x, y, n):
std = arr[x][y]
for i in range(x, x + n):
for j in range(y, y + n):
if std != arr[i][j]:
for a in range(2):
for b in range(2):
divide_arr(x + a * n // 2, y + b * n // 2, n // 2)
return
data[std] += 1
divide_arr(0, 0, len(arr))
return data
arr = [[1,1,0,0],[1,0,0,0],[1,0,0,1],[1,1,1,1]]
#arr = [[1,1,1,1,1,1,1,1],[0,1,1,1,1,1,1,1],[0,0,0,0,1,1,1,1],[0,1,0,0,1,1,1,1],[0,0,0,0,0,0,1,1],[0,0,0,0,0,0,0,1],[0,0,0,0,1,0,0,1],[0,0,0,0,1,1,1,1]]
'Algorithm > Algorithm Problem' 카테고리의 다른 글
백준 11403 경로찾기(DFS,BFS, Floyd-Warshall) (0) | 2022.05.04 |
---|---|
프로그래머스 양궁대회(시뮬레이션, 그리디) (0) | 2022.04.14 |
백준 18243 Small World Network(플로이드-와샬, BFS) (0) | 2022.04.07 |
10816 숫자 카드 2(Hashmap, Counter) (0) | 2022.04.02 |
백준 1764 듣보잡(set() 자료형) (0) | 2022.03.26 |