๋ฌธ์
์ฝ๋
#include <string>
#include <vector>
using namespace std;
int sum,targets,answer;
void dfs(const vector<int>&numbers, int index, int sum){
if(index<numbers.size()){
dfs(numbers,index+1,sum+numbers[index]);
dfs(numbers,index+1,sum-numbers[index]);
}
else{
if(targets==sum)answer++;
return;
}
}
int solution(vector<int> numbers, int target) {
targets=target;
dfs(numbers,0,sum);
return answer;
}
'Algorithm ๐ง๐ปโ๐ป > ํ๋ก๊ทธ๋๋จธ์ค(Programmers)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ํธ๋ํฐ ๋ฒํธ ๊ฐ๋ฆฌ๊ธฐ( Level 1) (0) | 2021.10.23 |
---|---|
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ํฐ์ผ๋ชฌ( Level 2) (0) | 2021.10.23 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ํํ( Level 2) (0) | 2021.10.23 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ์นด์นด์ค ํ๋ ์ฆ ์ปฌ๋ฌ๋ง๋ถ( Level 2, 2017 ์นด์นด์ค ์ฝ๋ ์์ ) (0) | 2021.10.23 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ์ต๋๊ฐ๊ณผ ์ต์๊ฐ( Level 2) (0) | 2021.10.22 |
[c++] ํ๋ก๊ทธ๋๋จธ์ค - ์ฒด์ก๋ณต( Level 1) (0) | 2021.10.22 |
๋๊ธ