Skip to content

Commit

Permalink
중복조합 nHk = k+(n-1)Ck
Browse files Browse the repository at this point in the history
  • Loading branch information
NYeonK committed Jan 16, 2022
1 parent 8b623ee commit 4eb9027
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions Study/combination_with_repetition.py
Expand Up @@ -12,13 +12,10 @@

#------------------------------------------

# 배와 감에 대해 중복을 허용하여 세 개 선택
# (배3), (배2,감1), (배1,감2), (감3)
# 재귀를 사용한 조합

# 5H3 = 7C3 = 35

n, k = 5,3
A = ['귤', '감', '배', '떡', '돈']
n, k = 3,3
A = ['귤', '감', '배']
arr = [0]*k

def combi(level, start):
Expand All @@ -27,13 +24,8 @@ def combi(level, start):
print(arr)
return

# lelvel마다 시작점은 다르지만, 끝점은 다 똑같다.
# 그러므로 시작점은 받아오는 걸로 하고, 끝점은 데이터의 개수만큼이다.

for i in range(start, len(A)):
arr[level] = A[i]
combi(level+1, i)

combi(0,0)

# 조합과 달리, 중복조합은 전에 선택된 것부터 시작점으로 선택할 수 있다.

0 comments on commit 4eb9027

Please sign in to comment.