일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- LCS
- 나머지
- Kotlin
- 6603
- Python
- 파이썬
- permutation
- 순열
- 9095
- Combination
- expo
- 앱
- 코틀린
- 안드로이드
- 11057
- lcm
- 최소공배수
- 11053
- 11054
- 홈화면
- 1260
- itertools
- 괄호
- 코테
- 11기
- 백준
- 매일11시
- 뒤로가기
- Android
- 1182
- Today
- Total
목록1182 (2)
황소개발자
import sys input = sys.stdin.readline n, s = map(int, input().split()) lst = list(map(int, input().split())) ans = 0 def sub_sum(idx, total): global ans, s if idx == n: if total == s: ans += 1 return sub_sum(idx + 1, total) sub_sum(idx + 1, total + lst[idx]) sub_sum(0, 0) ans -= 1 if s == 0 else 0 print(ans)
import sys input = sys.stdin.readline n, s = map(int, input().split()) num_list = list(map(int, input().split())) ans = 0 def subSet(idx, total): global ans if idx >= n: return total += num_list[idx] if total == s: ans += 1 subSet(idx + 1, total - num_list[idx]) subSet(idx + 1, total) subSet(0, 0) print(ans) jaimemin 님의 c++ 풀이를 참고하였다. 재귀로 풀었다. Solution 각 원소는 그 원소가 포함되었는지 안되었는지로 나뉘어진다. 길이가 0인 것이 ..