-
[1182] 부분수열의 합 (Python)[Python] 알고리즘/Silver 2022. 4. 4. 13:24
[문제]
https://www.acmicpc.net/problem/1182
알고리즘 분류는 브루트포스 알고리즘, 백트래킹 입니다.
저는 python의 combinations를 사용하여 모든 경우의 수를 구한 뒤, 더한 결과를 비교하였습니다.
[코드]
import sys from itertools import combinations N, S = map(int, sys.stdin.readline().split()) li = list(map(int, sys.stdin.readline().split())) all_li = list() for i in range(1, N + 1): all_li += list(combinations(li, i)) cnt = 0 for i in all_li: if sum(i) == S: cnt += 1 print(cnt)
'[Python] 알고리즘 > Silver' 카테고리의 다른 글
[9184] 신나는 함수 실행 (Python) (1) 2022.04.12 [10819] 차이를 최대로 (Python) (0) 2022.04.12 [6603] 로또 (Python) (0) 2022.04.04 [1535] 안녕 (Python) (0) 2022.03.21 [1138] 한 줄로 서기 (Python) (0) 2022.03.18