링크 : https://school.programmers.co.kr/learn/courses/30/lessons/43165
#include <string>
#include <vector>
using namespace std;
int answer = 0;
void DFS(vector<int> numbers, int target, int idx, int value){
if(idx == numbers.size()){
if(target == value) answer++;
return;
}
DFS(numbers, target, idx + 1, value + numbers[idx]);
DFS(numbers, target, idx + 1, value - numbers[idx]);
}
int solution(vector<int> numbers, int target) {
DFS(numbers, target, 0, 0);
return answer;
}