From 702dfcf536e15ea064bc884a7872fac74db5d933 Mon Sep 17 00:00:00 2001 From: leebyeongman Date: Sun, 19 May 2019 18:39:23 +0900 Subject: [PATCH] =?UTF-8?q?[=EC=9D=B4=EB=B3=91=EB=A7=8C]=20=ED=83=80?= =?UTF-8?q?=EA=B2=9F=20=EB=84=98=EB=B2=84(Programmers)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../README.md" | 11 ++++++++++ .../solution.py" | 22 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 "\354\235\264\353\263\221\353\247\214/Programmers/\355\203\200\352\262\237 \353\204\230\353\262\204/README.md" create mode 100644 "\354\235\264\353\263\221\353\247\214/Programmers/\355\203\200\352\262\237 \353\204\230\353\262\204/solution.py" diff --git "a/\354\235\264\353\263\221\353\247\214/Programmers/\355\203\200\352\262\237 \353\204\230\353\262\204/README.md" "b/\354\235\264\353\263\221\353\247\214/Programmers/\355\203\200\352\262\237 \353\204\230\353\262\204/README.md" new file mode 100644 index 0000000..2950a07 --- /dev/null +++ "b/\354\235\264\353\263\221\353\247\214/Programmers/\355\203\200\352\262\237 \353\204\230\353\262\204/README.md" @@ -0,0 +1,11 @@ +[Programmers](https://programmers.co.kr/learn/courses/30/lessons/43165). + +Problem : 타겟 넘버 **DFS/BFS** + +Flow : + +1. n개의 음이 아닌 정수가 있습니다. 이 수를 적절히 더하거나 빼서 타겟 넘버를 만든다. + +Solution : +1. 배열에 있는 값으로 만들수 있는 모든 경우를 구해야할 것 같다. +2. 음... 경우의 수로 해야하나.. diff --git "a/\354\235\264\353\263\221\353\247\214/Programmers/\355\203\200\352\262\237 \353\204\230\353\262\204/solution.py" "b/\354\235\264\353\263\221\353\247\214/Programmers/\355\203\200\352\262\237 \353\204\230\353\262\204/solution.py" new file mode 100644 index 0000000..3248c07 --- /dev/null +++ "b/\354\235\264\353\263\221\353\247\214/Programmers/\355\203\200\352\262\237 \353\204\230\353\262\204/solution.py" @@ -0,0 +1,22 @@ +cnt = 0 + + +def func(numbers, target, curr, idx): + global cnt + if idx == len(numbers): + if curr == target: + cnt += 1 + return + else: + func(numbers, target, curr + numbers[idx], idx+1) + func(numbers, target, curr - numbers[idx], idx+1) + + +def solution(numbers, target): + global cnt + func(numbers, target, 0, 0) + answer = cnt + return answer + +if __name__ == '__main__': + solution([1, 1, 1, 1, 1], 3)