0%

BOJ 5568

Input

첫째 줄에 n이,

둘째 줄에 k가 주어진다.

셋째 줄부터 n개 줄에는 카드에 적혀있는 수가 주어진다.

1
2
3
4
5
6
import sys
input = sys.stdin.readline

n = int(input().rstrip())
k = int(input().rstrip())
s = [input().strip() for _ in range(n)]

Brute Force

  • 순회하는 순서에 따라 조합이 달라짐 = 순열

    python library itertools.permutations

    • input: iterable[, choice]
    • output: possible combinations (iterable)
    1
    2
    3
    # 순열
    # nPk
    from itertools import permutations
  • 결과가 같은 경우는 제외 = set

    1
    ret = set()
    1
    2
    3
    # k-length possible combinations (tuples)
    for per in permutations(s, k):
    ret.add(''.join(per))

Output

첫째 줄에 상근이가 만들 수 있는 정수의 개수를 출력한다.

1
print(len(ret))