~๋ชฉ์ฐจ~
๋ฌธ์
๋ฌธ์ ํด๊ฒฐ ํฌ์ธํธ
- BFS๋ฅผ ์ด์ฉํ์ฌ ๊ฐ ์ซ์๋ฅผ ๋ํ ๊ฒฝ์ฐ, ๋ํ์ง ์์ ๊ฒฝ์ฐ๋ฅผ ๋ชจ๋ ๋ฐฉ๋ฌธ
- ๋ชจ๋ ์ซ์๋ฅผ ๋์์ ๋ ์ฐพ๋ ๊ฐ์ด๋ผ๋ฉด ํด๋น ๊ฒฝ์ฐ ์นด์ดํธ
- ํ๋ก๊ทธ๋๋จธ์ค 'ํ๊ฒ ๋๋ฒ'์ ํด๊ฒฐ ํฌ์ธํธ๊ฐ ์ ์ฌํ๋ฏ๋ก ์ฐธ๊ณ ํ์ธ์
์์ฑ ์ฝ๋
from collections import deque
for test in range(1, int(input())+1):
result = 0
que = deque()
N, K = list(map(int, input().split()))
numbers = list(map(int, input().split()))
que.append((1, numbers[0]))
que.append((1, 0))
while que:
q = que.popleft()
if q[0] == N:
if q[1] == K:
result += 1
else:
que.append((q[0]+1, q[1] + numbers[q[0]]))
que.append((q[0]+1, q[1]))
print('#{} {}'.format(test, result))
๋์์ด ๋์ จ๋ค๋ฉด ์ข์์ ๋๋ฌ์ฃผ์ธ์๐
'๐๋ฌธ์ ํ์ด > ๐งฉSWExpertAcademy' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[SWEA] ํ์ด์ฌ 1216. ํ๋ฌธ2 | ๊ทธ๋ฆฌ๋ ์๊ณ ๋ฆฌ์ฆ (0) | 2023.04.26 |
---|---|
[SWEA] ํ์ด์ฌ 220. Magnetic | ๊ทธ๋ฆฌ๋ ์๊ณ ๋ฆฌ์ฆ (0) | 2023.04.25 |
[SWEA] ํ์ด์ฌ 2806. N-Queen | ๋ฐฑํธ๋ํน(Backtracking) (0) | 2023.04.21 |
[SWEA] ํ์ด์ฌ 5215. ํ๋ฒ๊ฑฐ ๋ค์ด์ดํธ | DFS (2) | 2023.04.20 |
[SWEA] ํ์ด์ฌ 1209. Sum (0) | 2023.04.20 |