BOJ 1182 c++

Algorithm / / 2020. 7. 14. 22:24

알고리즘

백준 1182, BOJ 1182 부분수열의 합 c++

#include <bits/stdc++.h>
using namespace std;
int n, s;
int arr[21];
int cnt = 0;

void func(int cur, int total) {
    if (cur == n) {
        if (total == s) {
            cnt++;
        }
        return;
    }
    func(cur + 1, total);
    func(cur + 1, arr[cur] + total);
}

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 -= 1;
    cout << cnt;
}

'Algorithm' 카테고리의 다른 글

BOJ 11726 c++  (0) 2020.07.15
BOJ 9663 c++  (0) 2020.07.14
BOJ 11728 c++  (0) 2020.07.14
BOJ 15694 c++  (0) 2020.07.13
BOJ 1074 c++  (0) 2020.07.13
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기
// custom