From c1d3dd429894f898add1654b8ff5c45ce885c331 Mon Sep 17 00:00:00 2001 From: ZeVicTech Date: Sat, 11 Feb 2023 23:13:01 +0900 Subject: [PATCH] =?UTF-8?q?=EC=96=91=EA=B6=81=EB=8C=80=ED=9A=8C=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...21\352\266\201\353\214\200\355\232\214.py" | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 "\353\271\204\355\212\270\353\247\210\354\212\244\355\202\271/\354\226\221\352\266\201\353\214\200\355\232\214.py" diff --git "a/\353\271\204\355\212\270\353\247\210\354\212\244\355\202\271/\354\226\221\352\266\201\353\214\200\355\232\214.py" "b/\353\271\204\355\212\270\353\247\210\354\212\244\355\202\271/\354\226\221\352\266\201\353\214\200\355\232\214.py" new file mode 100644 index 0000000..ad5f560 --- /dev/null +++ "b/\353\271\204\355\212\270\353\247\210\354\212\244\355\202\271/\354\226\221\352\266\201\353\214\200\355\232\214.py" @@ -0,0 +1,47 @@ +# https://school.programmers.co.kr/learn/courses/30/lessons/92342 + +# 이진수를 활용한 비트마스킹 기법을 처음 배워서 사용했다. +# 이진수를 사건이 일어난 경우와 일어나지 않는 경우를 각각 1과 0으로 매칭할 수 있다는 것을 배움 + +def solution(n, info): + answer = [0] * 11 + tmp = [0] * 11 + maxDiff = 0 + + for subset in range(1<<10): + cnt = 0 + ryan = 0 + appeach = 0 + for i in range(11): + if subset & (1< n: + continue + + tmp[10] = n - cnt + + if ryan-appeach == maxDiff: + for i in reversed(range(11)): + if tmp[i] > answer[i]: + answer = tmp[:] + break + if tmp[i] < answer[i]: + break + + elif ryan-appeach > maxDiff: + maxDiff = ryan-appeach + answer = tmp[:] + + if maxDiff == 0: + answer = [-1] + + return answer + +solution(5,[2,1,1,1,0,0,0,0,0,0,0]) \ No newline at end of file