타겟 넘버 소스코드1 [ 프로그래머스 / DFS ] 타겟 넘버 1. 문제 코딩테스트 연습 - 타겟 넘버 n개의 음이 아닌 정수가 있습니다. 이 수를 적절히 더하거나 빼서 타겟 넘버를 만들려고 합니다. 예를 들어 [1, 1, 1, 1, 1]로 숫자 3을 만들려면 다음 다섯 방법을 쓸 수 있습니다. -1+1+1+1+1 = 3 +1-1+1+1+ programmers.co.kr 2. 소스코드 - 매우 간단한 DFS문제 소스코드 #include #include using namespace std; int ans, t; vectorcopy_numbers; void dfs(int sum, int depth){ if(depth >= copy_numbers.size()) { if(sum == t) ans++; return; } dfs(sum + copy_numbers[depth] .. 2020. 6. 30. 이전 1 다음