
백준 6603 로또 (파이썬, 자바)
2022. 12. 12. 21:30
백준
풀이 1 (재귀 함수) import sys # N과 M을 풀었다면 똑같이 풀면 됨 def solve(depth, K): if depth == 6: print(*ans) return for i in S: if visited[i]: continue if not ans: ans.append(i) visited[i] = 1 solve(depth + 1, K) ans.pop() visited[i] = 0 elif i > ans[-1]: ans.append(i) visited[i] = 1 solve(depth+1, K) ans.pop() visited[i] = 0 while 1: K, *S = map(int, sys.stdin.readline().split()) if K == 0: break visited = [0..

itertools 순열과 조합 라이브러리 (파이썬)
2022. 9. 19. 19:15
카테고리 없음
순열 permutations(반복 가능한 객체, n) // n은 몇 개 뽑을지 중복 허용하지 않음 순서에 의미가 없음 from itertools import permutations print(list(permutations([1,2,3,4], 2))) # [(1, 2), (1, 3), (1, 4), (2, 1), (2, 3), (2, 4), (3, 1), (3, 2), (3, 4), (4, 1), (4, 2), (4, 3)] 중복 순열 product(반복 가능한 객체, n) // n은 몇 개 뽑을지 중복 허용 from itertools import product print(list(product([1,2,3,4], repeat=2))) # [(1, 1), (1, 2), (1, 3), (1, 4), (2,..