From 8a98570f72968bd0289029569634a5766afd7cf6 Mon Sep 17 00:00:00 2001 From: park jiyeong Date: Fri, 16 Aug 2024 01:09:11 +0900 Subject: [PATCH] 50! --- JYPARK/41to50/50.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 JYPARK/41to50/50.py diff --git a/JYPARK/41to50/50.py b/JYPARK/41to50/50.py new file mode 100644 index 0000000..21eb1cf --- /dev/null +++ b/JYPARK/41to50/50.py @@ -0,0 +1,19 @@ +def solution(n): + def check(ls, new): + for i in range(len(ls)): + if new == ls[i] or (len(ls)-i) == abs(ls[i]-new): + return False + return True + def dfs(n, ls): + if len(ls) == n: + return 1 + cnt = 0 + for i in range(n): + if check(ls, i): + cnt += dfs(n, ls+[i]) + return cnt + + return dfs(n, []) + +n = 4 +print(solution(n))