프로그래밍/Python
백준_python 23057번 도전 숫자왕 (set, combinations)
O'bin
2024. 6. 19. 23:49
<문제 링크>
https://www.acmicpc.net/problem/23057
<정답 코드>
sol ) combinations로 조합을 뽑고, set에 합 저장
1
2
3
4
5
6
7
8
9
10
11
12
13
|
from itertools import combinations
n = int(input())
nums = list(map(int, input().split()))
m = sum(nums)
sums = set()
for i in range(1, n+1):
for j in combinations(nums, i):
sums.add(sum(j))
print(m - len(sums))
|
cs |
set()를 사용해 중복을 고려하지 않고 모든 조합의 합을 저장한다.
m에서 sums의 길이를 빼면 만들어지지 않은 수의 개수를 얻게 된다.