https://school.programmers.co.kr/learn/courses/30/lessons/43165
#include <string>
#include <vector>
using namespace std;
vector<int> num;
int targ, answer;
void recur(int idx, int res) {
if (idx == num.size()) {
if (res == targ)
answer++;
return ;
}
recur (idx + 1, res - num[idx]);
recur (idx + 1, res + num[idx]);
}
int solution(vector<int> numbers, int target) {
num = numbers;
targ = target;
answer = 0;
recur(0, 0);
return answer;
}
오늘은 두문제~~
'<algorithm> > 프로그래머스' 카테고리의 다른 글
프로그래머스 야근 지수 c++ (0) | 2023.07.30 |
---|---|
프로그래머스 네트워크 c++ (2) | 2023.07.03 |
프로그래머스 뉴스 클러스터링 c++ (0) | 2023.07.02 |
프로그래머스 정수 삼각형 c++ (2) | 2023.06.28 |
프로그래머스 할인 행사 c++ (4) | 2023.06.24 |