황소개발자
백준 15686 파이썬 python : 치킨 배달 @@황소처럼 우직하게@@ 치킨 먹고싶어 본문
반응형
2 의 13승은 작은 숫자 베이베
import sys
import itertools
input = sys.stdin.readline
n, m = map(int, input().split())
mat = []
for i in range(n):
mat.append(list(map(int, input().split())))
homes = []
chickens = []
for i in range(n):
for j in range(n):
if mat[i][j] == 1:
homes.append([i, j])
elif mat[i][j] == 2:
chickens.append([i, j])
combi = [i for i in range(len(chickens))]
combi = list(itertools.combinations(combi, m))
# print(combi)
ans = 999999999
for case in combi:
dist = [999999999 for i in range(len(homes))]
for i in case: # 치킨 번호
for j in range(len(homes)):
dist[j] = min(dist[j], abs(homes[j][0] - chickens[i][0]) + abs(homes[j][1] - chickens[i][1]))
ans = min(ans, sum(dist))
print(ans)
반응형
'백준 문제 풀이' 카테고리의 다른 글
백준 11060 파이썬 python : 점프 점프 @@황소처럼 우직하게@@ 뭐냐 싱겁게 (0) | 2020.04.23 |
---|---|
백준 2210 파이썬 python : 숫자판 점프 @@황소처럼 우직하게@@ 좋은사람만나 사랑받고 (0) | 2020.04.23 |
백준 17088 파이썬 python : 등차수열 변환 @@황소처럼 우직하게@@ 졸려뒤지것네 (0) | 2020.04.23 |
백준 16637 파이썬 python : 괄호 추가하기 @@황소처럼 우직하게@@ 요샌풀면 "이게 되네" (0) | 2020.04.22 |
python permutations combinations 파이썬 순열 조합 itertools 모듈 사용. 사용법 정리. 문제점과 한계. 그리고 해결책 (0) | 2020.04.22 |
Comments