[백준] 1182 부분수열의 합

0

백준

목록 보기
199/271
post-thumbnail
post-custom-banner

[백준] 1182 부분수열의 합

#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int n, s;
	cin >> n >> s;

	vector<int> arr;
	for (int i = 0; i < n; ++i) {
		int input;
		cin >> input;
		arr.push_back(input);
	}

	int cnt = 0;
	long long set;
	for (set = 1LL; set < (1 << n); set++) {
		int sum = 0;
		for (int i = 0; i < n; ++i) {
			if (set & (1 << i)) sum += arr[i];
		}
		if (sum == s)cnt++;
	}
	cout << cnt;
	return 0;
}
profile
Be able to be vulnerable, in search of truth
post-custom-banner

0개의 댓글