Recent Posts
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Today
Total
관리 메뉴

Try

[Programmers/C++] 타겟 넘버 본문

Algorithm/Programmers

[Programmers/C++] 타겟 넘버

HAS3ONG 2018. 11. 12. 16:52

출처


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();
}


Comments