코딩 테스트/Baekjoon

S3 15652. N과 M (4)

  • -
728x90

  • 정답률 : 78%

 


def product(n,new,c): global arr answer = [] if len(new) == n: return [new] for i in range(c,len(arr)): answer.extend(product(n,new+[arr[i]],i)) return answer n,m = map(int,input().split()) arr = list(i for i in range(1,n+1)) visited = [False]*(n) for p in product(m,[],0): print(*p, sep=' ')

product는 permutations에서 중복을 허용한건데,
이번에는 오른쪽에 왼쪽 원소보다 큰 원소가 와야하는 조건이 추가됐다.

그래서 index를 추가해서 함수를 바꿨다.

320x100

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.