백준 14225번 부분수열의 합 (Python 3)
2022. 9. 1. 14:28ㆍProblem solving
Baekjoon online judge 14225번 파이썬
링크
https://www.acmicpc.net/problem/14225
14225번: 부분수열의 합
수열 S가 주어졌을 때, 수열 S의 부분 수열의 합으로 나올 수 없는 가장 작은 자연수를 구하는 프로그램을 작성하시오. 예를 들어, S = [5, 1, 2]인 경우에 1, 2, 3(=1+2), 5, 6(=1+5), 7(=2+5), 8(=1+2+5)을 만들
www.acmicpc.net
단순하게 combinations로 부분 집합 모두 구해서 풀었다
소스코드
import sys
from collections import deque
from itertools import combinations
input = sys.stdin.readline
result=set()
n=int(input())
s=list(map(int,input().split()))
for i in range(1,n+1):
possible=combinations(s,i)
for p in possible:
result.add(sum(p))
for i in range(1,2000000):
if i not in result:
print(i)
break
'Problem solving' 카테고리의 다른 글
백준 2003번 수들의 합 2 (Python 3) (0) | 2022.09.01 |
---|---|
백준 16198번 에너지 모으기 (Python 3) (0) | 2022.09.01 |
백준 2234번 성곽 (Python 3) (0) | 2022.08.31 |
백준 9376번 탈옥 (Python 3) (0) | 2022.08.31 |
백준 1600번 말이 되고픈 원숭이 (Python 3) (0) | 2022.08.30 |