-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
16-janghw0126 #66
16-janghw0126 #66
Conversation
def backtracking(depth): | ||
#νμ¬κΉμ§ μ νν μ«μμ κ°μκ° Mκ³Ό κ°λ€λ©΄ μνν λ¬Έμ΄λ€. | ||
if depth == M: | ||
#λ°μ€μ μ μ₯λ μ«μλ€μ λ¬Έμμ΄λ‘ λ³ννμ¬ κ³΅λ°±μ κΈ°μ€μΌλ‘ κ²°ν©νμ¬ μΆλ ₯νλ€. | ||
print(' '.join(map(str,box))) | ||
return | ||
#0λΆν° N-1κΉμ§μ μΈλ±μ€μ λν΄ λ°λ³΅νλ€. | ||
for i in range(N): | ||
#μ΄λ―Έ μ νλ μ«μλΌλ©΄ 건λλ΄λ€. | ||
if numbers[i] in box: | ||
continue | ||
#μ«μλ₯Ό λ°μ€μ μΆκ°νλ€. | ||
box.append(numbers[i]) | ||
#λ€μ μλ¦Ώμμ μ«μλ₯Ό μ ννκΈ° μν΄ μ¬κ·μ μΌλ‘ backtracking ν¨μλ₯Ό νΈμΆνλ€. | ||
backtracking(depth + 1) | ||
#ν¨μ νΈμΆ νμλ ν΄λΉ μλ¦Ώμμμμ μ νμ΄ λλ¬μΌλ―λ‘, λ°μ€μμ λ§μ§λ§μ μΆκ°λ μ«μλ₯Ό μ κ±°νλ€. | ||
box.pop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ λ κ°μ λ°©λ²μΌλ‘ νμμλ€μ γ γ
input = open(0).readline
n,m = map(int,input().split())
nlist = sorted(list(map(int,input().split())))
result = []
def dfs(depth):
if len(result) == m:
return print(*result)
for i in nlist:
if i not in result:
result.append(i)
dfs(depth + 1)
result.pop()
dfs(0)
μ΄λ κ² λ¦¬μ€νΈ μμμ λ°λ‘ μ κ·Όν΄μ μ«μλ₯Ό μ μ₯νκ³ μΆλ ₯μ ν μλ μμ΅λλ€ !
μ¬ν μ€λΉλ‘ λ°μμ ¨μν λ° μ μ±μ€λ¬μ΄ PR λ¨κ²¨μ£ΌμλλΌ κ³ μνμ ¨μ΅λλ€ !! βοΈπ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
νμλκ³Ό μ μλμ μ½λλ₯Ό 보며 λ€μνκ² μ½λλ₯Ό 지 μ μλ€λ κ²μ λ€μκΈ λλλλ€π€
μ΄λ² μ°¨μ PR μμ±νμλλΌ μκ³ λ§μΌμ
¨μ΅λλ€ ππ»π
π λ¬Έμ λ§ν¬
λ°±μ€ | Nκ³Ό M (5)
λ¬Έμ μ€λͺ
μ ν 쑰건
μ λ ₯
μΆλ ₯
βοΈ μμλ μκ°
1μκ°
β¨ μλ μ½λ
β μ΄ λ¬Έμ μ μμ΄λμ΄λ μ£Όμ΄μ§ μ«μλ€μ λ°°μ΄λ‘ λ°μ λ€ μ λ ¬νκ³ , μμ΄λ‘ λ§λ λ€λ κ²μ΄λ€. κ·Έλμ λ°±νΈλνΉ μκ³ λ¦¬μ¦μ μ νμ λ§κ², λͺ¨λ κ²½μ°μ μμ΄μ μ¬κ·μ μΌλ‘ νμνμ¬ μΆλ ₯νμλ€. μ΄λ, μ¬μ μμλλ‘ κ²°κ³Όκ°μ μΆλ ₯νλ κ²μ΄κΈ° λλ¬Έμ DFS λ°©μμΌλ‘ κ²½μ°λ₯Ό νμνλ κ²μ΄ λ μ μ ν κ² κ°μλ€.
πνμ΄ λ°©λ²
backtracking(depth)
ν¨μλ₯Ό μ μΈνλ€.β¬οΈμ 체 μ½λ
π μλ‘κ² μκ²λ λ΄μ©
.