-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0977f03
commit 702dfcf
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. 음... 경우의 수로 해야하나.. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |