하다보니
1182번-부분수열의 합 본문
#include<iostream>
using namespace std;
int arr[30];
int n, s;
int cnt = 0;
void func(int cur,int tot) {
if (cur == n) {
if (tot == s) {
cnt++;
}
return;
}
func(cur + 1, tot);
func(cur + 1, tot + arr[cur]);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> s;
for (int i = 0; i < n; i++)
cin >> arr[i];
func(0, 0);
if (s == 0)
cnt--;
cout << cnt;
}
'알고리즘 풀이 > 백준' 카테고리의 다른 글
15651번-n과 m(3) (0) | 2022.03.08 |
---|---|
15650번-n과 m (2) (0) | 2022.03.08 |
n과 m(1) (0) | 2022.03.08 |
3986번-좋은 단어 (0) | 2022.03.07 |
3986번-균형 잡힌 세상 (0) | 2022.03.07 |