Skip to content

Commit

Permalink
[이병만] 타겟 넘버(Programmers)
Browse files Browse the repository at this point in the history
  • Loading branch information
Only-bottle committed May 19, 2019
1 parent 0977f03 commit 702dfcf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions 이병만/Programmers/타겟 넘버/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Programmers](https://programmers.co.kr/learn/courses/30/lessons/43165).

Problem : 타겟 넘버 **DFS/BFS**

Flow :

1. n개의 음이 아닌 정수가 있습니다. 이 수를 적절히 더하거나 빼서 타겟 넘버를 만든다.

Solution :
1. 배열에 있는 값으로 만들수 있는 모든 경우를 구해야할 것 같다.
2. 음... 경우의 수로 해야하나..
22 changes: 22 additions & 0 deletions 이병만/Programmers/타겟 넘버/solution.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 702dfcf

Please sign in to comment.