Try
[Programmers/C++] 타겟 넘버 본문
출처
https://programmers.co.kr/learn/courses/30/lessons/43165
소스
/*/*/* khsh5592@naver.com/* has3ong.tistory.com/*/* 2018 - 11 - 12/**/#include<stdio.h>#include<iostream>#include<conio.h>#include<string>#include<vector>int answer = 0;using namespace std;void solution(vector<int> numbers, int target, int index){int sum;if(index < numbers.size()){numbers[index] = numbers[index] * 1;solution(numbers, target, index+1);numbers[index] = numbers[index] * -1;solution(numbers, target, index+1);}else{sum = 0;for(int i = 0 ; i < numbers.size(); i++){sum = sum + numbers[i];}if( target == sum){answer++;}else{}}}void main(){vector<int> numbers(5,1);solution(numbers, 3, 0);cout << answer << endl;getch();}
'Algorithm > Programmers' 카테고리의 다른 글
[Programmers/C++] 카펫 (0) | 2018.11.12 |
---|---|
[Programmers/C++] 최빈값 구하기 (0) | 2018.11.12 |
[Programmers/C++] 피보나치 시저 암호 (0) | 2018.11.12 |
[Programmers/C++] Ugly Number 구하기 (0) | 2018.11.12 |
[Programmers/C++] 배열의 중복된 값 찾기. (0) | 2018.11.11 |
Comments