<문제 링크>
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의 길이를 빼면 만들어지지 않은 수의 개수를 얻게 된다.
'프로그래밍 > Python' 카테고리의 다른 글
백준_python 1149번 RGB거리 (DP) (0) | 2024.07.30 |
---|---|
백준_python 11053번 가장 긴 증가하는 부분 수열 (DP) (0) | 2024.07.29 |
백준_python 2910번 빈도 정렬 (해시, 정렬, lambda) (0) | 2024.06.17 |
백준_python 2579번 계단 오르기 (DP) (0) | 2024.06.14 |
백준_python 15686번 치킨 배달(combiantions, 백트래킹) (1) | 2024.06.13 |