[ SW Expert Academy ] 5247. 연산
보자마다 dfs라고 생각했다.. 그런데 maximum recursion depth exceeded 에러가 나서 읭? 왜 깊이 제한 에러가 나지..? 회귀하도록 조건 잘 걸어준 것 같은데...? def dfs(current, m, depth): global answer if current > 100000 or depth >= answer: return if current == m: answer = min(answer, depth) return dfs(current+1, m, depth+1) dfs(current-1, m, depth+1) dfs(current*2, m, depth+1) dfs(current-10, m, depth+1) if __name__ == "__main__": T = int(input..
[ SW Expert Academy ] 5208 전기버스2
음 .. 언제쯤 재귀를 자유자재로 사용할까.. 꽤 속상하네? 제출도 못 하고 돌아가지 않는 내 문제 풀이.. def get_min_exchange(n, bus_stops, now, cnt): global min_cnt if min_cnt = n: # 카운트 최솟값인지 체크해서 갱신 min_cnt = min(min_cnt, cnt) return for i in range(now+1, now + bus_stops[now]): get_min_exchange(n, bus_stops, i, cnt + 1) import sys sys.stdin = open("sample.txt", "r") if __name__ == '__main__': T = int(input()) for test_case in range(1, ..
[ SW Expert Academy ] 5188. 최소합
헐.. 드디어 재귀를 잘 다룰 수 있게 된건가..? 재귀 구현 한 큐에 성공한 게 처음이라서 얼떨떨하다.. 1차 시도. [ 10 /10 ]. Pas def search(x, y, n, board, visited, total): total += board[x][y] global total_min if x == n - 1 and y == n - 1: total_min = min(total_min, total) return # 오른쪽 if x + 1 < n: search(x+1, y, n, board, visited, total) # 아래쪽 if y + 1 < n: search(x, y+1, n, board, visited, total) T = int(input()) for test_case in range(..