Notice
Recent Posts
Recent Comments
Link
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
Tags
- ๊ตญ๋น์ง์
- node.js
- react
- CSS
- KDT
- ๋ฐฑ์ค
- ์ฝ๋ฉ
- Python
- error
- ํ๋ก๊ทธ๋๋จธ์ค
- heapq
- fe
- ์ฝ๋ฉ์ ํ
- ํ ์ดํ๋ก์ ํธ
- HTML
- ๋๋ฆผ์ฝ๋ฉ
- ๊ฐ๋ฐ
- javascript
- ์๊ณ ๋ฆฌ์ฆ
- ์ฝ๋ฉํ ์คํธ
- ๊ทธ๋ฆฌ๋
- ํ๋ก์ ํธ
- ํฌ๋กค๋ง
- Til
- ํ๋ก ํธ์๋
- ๋ชจ๊ฐ์ฝ
- ํ์ด์ฌ
- mongodb
- JS
- ๋ ธ๋ง๋์ฝ๋
Archives
- Today
- Total
๐ฑ → ๐ณ
[Baekjoon] 7490. 0 ๋ง๋ค๊ธฐ - python ๋ณธ๋ฌธ
728x90
https://www.acmicpc.net/problem/7490
7490๋ฒ: 0 ๋ง๋ค๊ธฐ
๊ฐ ํ ์คํธ ์ผ์ด์ค์ ๋ํด ASCII ์์์ ๋ฐ๋ผ ๊ฒฐ๊ณผ๊ฐ 0์ด ๋๋ ๋ชจ๋ ์์์ ์ถ๋ ฅํ๋ค. ๊ฐ ํ ์คํธ ์ผ์ด์ค์ ๊ฒฐ๊ณผ๋ ํ ์ค์ ๋์ ๊ตฌ๋ถํ๋ค.
www.acmicpc.net
์ค๊ณ ๋ฐฉ๋ฒ
์ฌ๊ท
sum : ํ์ฌ๊น์ง์ ์ฐ์ฐ๊ฐ
sign : ๋ค์ ์ฐ์ฐ์ num๊ณผ ํจ๊ป ๋ค์ด๊ฐ ์ฐ์ฐ์(+๋ 1๋ก, -๋ -1๋ก ํํ, ๋น์นธ์ด ๋ค์ด๊ฐ๋๋ ๋ฌด์๋ฏธํจ)
num : ๋ค์์ ์ฐ์ฐ๋ ์ซ์
n : ๋ช๋ฒ์งธ ํญ์ธ์ง๋ฅผ ๋ํ๋
string : ํ์ฌ๊น์ง์ ํํ์
์ฝ๋
def recur(sum, sign, num, n, string):
if (n == N):
sum = sum + (sign*num)
if sum == 0:
print(string)
else:
recur(sum ,sign ,num*10+(n+1), n+1, string+' '+str(n+1))
recur(sum+sign*num ,1 ,(n+1), n+1, string+'+'+str(n+1))
recur(sum+sign*num, -1, (n+1), n+1, string+'-'+str(n+1))
test_case = int(input())
for _ in range(test_case):
N = int(input())
recur(0,1,1,1,"1")
print()
์ฐธ๊ณ : https://velog.io/@tks7205/%EB%B0%B1%EC%A4%80-7490-0%EB%A7%8C%EB%93%A4%EA%B8%B0backtracking
728x90
'Algorithms' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Baekjoon] 4963. ์ฌ์ ๊ฐ์ - python (0) | 2023.10.27 |
---|---|
[Baekjoon] 1926. ๊ทธ๋ฆผ - python (0) | 2023.10.03 |
[Baekjoon] 14281. ๋ณผ๋ก ์์ด - python (0) | 2023.10.02 |
[Baekjoon] 1469. ์ ์ฌ์ด ์์ด - python (0) | 2023.09.29 |
[Baekjoon] 17392. ์ฐ์ธํ ๋ฐฉํ - python (0) | 2023.09.29 |