๐งฎ PS
๋ฐฑ์ค (boj) ํ์ด์ฌ - 1182 ๋ฒ : ๋ถ๋ถ์์ด์ ํฉ
Newmon
2020. 5. 12. 17:51
๋ฌธ์ ๋งํฌ :https://www.acmicpc.net/problem/1182
itertools์ combination์ ์ฌ์ฉํ์ฌ ํ์๋ค. (์๋์ผ๋ก n๊ฐ์ค์ r๊ฐ๋ฅผ ๋ฝ๋ ์กฐํฉ(combination)์ ๋ฐํํด์ฃผ๋... )
https://infinitt.tistory.com/114
๋ฌธ์ ์์ N๊ณผ S๋ฅผ ์ ๋ ฅ์ผ๋ก ์ค๋ค.
N๊ฐ์ ์ ์๋ก ์ด๋ฃจ์ด์ง ์์ด์ค์, ?๊ฐ๋ฅผ ๋ฝ์ ๊ทธ ํฉ์ด S์ ๊ฐ์์ผ ํ๋ฏ๋ก ์กฐํฉ์ ์ฌ์ฉํ๋ฉด ๋๋ค.
from itertools import combinations
N, S = map(int,input().split())
arr = list(map(int,input().split()))
cnt = 0
for i in range(1,len(arr)+1):
answer = list(combinations(arr,i))
for idx in range(len(answer)):
sum_partier = sum(answer[idx])
if sum_partier == S :
cnt += 1
print(cnt)