알고리즘 풀이/백준

1182번-부분수열의 합

claire 2022. 3. 8. 13:36
#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;

}