Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions froglike6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
---
26 changes: 26 additions & 0 deletions froglike6/backtracking/15686.py
Original file line number Diff line number Diff line change
@@ -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)