Skip to content

Commit

Permalink
Merge pull request #140 from AlgoLeadMe/35-Munbin-Lee
Browse files Browse the repository at this point in the history
35-Munbin-Lee
  • Loading branch information
MunbinLee authored Feb 25, 2024
2 parents af790fe + b3f3032 commit a4f74d3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions Munbin-Lee/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@
| 32차시 | 2024.01.30 | 백트래킹 | <a href="https://www.acmicpc.net/problem/17114">하이퍼 토마토</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/124 |
| 33차시 | 2024.02.04 | 정수론 | <a href="https://www.acmicpc.net/problem/14905">소수 4개의 합</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/128 |
| 34차시 | 2024.02.06 | 구현 | <a href="https://www.acmicpc.net/problem/1756">피자 굽기</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/133 |
| 35차시 | 2024.02.18 | 백트래킹 | <a href="https://www.acmicpc.net/problem/24891">단어 마방진</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/140 |
---
22 changes: 22 additions & 0 deletions Munbin-Lee/백트래킹/35-단어 마방진.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from itertools import permutations

stdin = open(0)

L, N = map(int, stdin.readline().split())
words = sorted(stdin.read().splitlines())

# 단어 순열 x가 단어 마방진인지 확인하는 함수
def isValid(x):
for i in range(L):
for j in range(L):
if x[i][j] != x[j][i]: return False

return True

for perm in permutations(words, L):
if not isValid(perm): continue

print(*perm, sep='\n')
exit()

print('NONE')

0 comments on commit a4f74d3

Please sign in to comment.