diff --git a/froglike6/README.md b/froglike6/README.md index 3e35a97..94a1583 100644 --- a/froglike6/README.md +++ b/froglike6/README.md @@ -14,4 +14,5 @@ | 10차시 | 2025.05.08 | 이분탐색 | [게임](https://www.acmicpc.net/problem/1072)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/42| | 11차시 | 2025.05.08 | 조합론 | [High Towers](https://www.acmicpc.net/problem/33785)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/43| | 12차시 | 2025.05.11 | 자료 구조 | [AC](https://www.acmicpc.net/problem/5430)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/46| + | 13차시 | 2025.05.13 | 백트래킹 | [치킨 배달](https://www.acmicpc.net/problem/15686)|https://github.com/AlgoLeadMe/AlgoLeadMe-13/pull/47| --- diff --git a/froglike6/backtracking/15686.py b/froglike6/backtracking/15686.py new file mode 100644 index 0000000..b59a059 --- /dev/null +++ b/froglike6/backtracking/15686.py @@ -0,0 +1,26 @@ +import sys +from itertools import combinations +input = sys.stdin.readline + +N, M = map(int, input().split()) +houses = [] +chickens = [] +for r in range(N): + row = list(map(int, input().split())) + for i, v in enumerate(row): + if v == 1: + houses.append((r, i)) + elif v == 2: + chickens.append((r, i)) + +min_city_dist = float('inf') +for comb in combinations(chickens, M): + city_dist = 0 + for hr, hc in houses: + dist = min(abs(hr-cr) + abs(hc-cc) for cr, cc in comb) + city_dist += dist + if city_dist >= min_city_dist: + break + min_city_dist = min(min_city_dist, city_dist) + +print(min_city_dist) \ No newline at end of file