본문 바로가기
  • KEEP HUSTLE!

전체 글73

[백준 1463] 1로 만들기 - Python(파이썬) 초기 답안(BFS) import sys def solution(N): ans = 0 while N: temp = [] for n in N: if n == 1: return ans if not n % 3: temp.append(n // 3) if not n % 2: temp.append(n // 2) if n - 1 > 0: temp.append(n - 1) ans += 1 N = temp N = int(sys.stdin.readline().strip()) arr = [N] print(solution(arr)) 최적화 답안 import sys def solution(N): if N in answer: return answer[N] answer[N] = 1 + min(solution(N // 3) + N %.. 2021. 2. 22.
[백준 10844] 쉬운 계단 수 - Python(파이썬) import sys N = int(sys.stdin.readline().strip()) answer = [[0]*10 for _ in range(N+1)] for i in range(1, 10): answer[0][i] = 1 for i in range(1, N+1): for j in range(10): if j == 0: answer[i][j] = answer[i - 1][j + 1] elif j == 9: answer[i][j] = answer[i - 1][j - 1] else: answer[i][j] = answer[i - 1][j - 1] + answer[i - 1][j + 1] print(sum(answer[N-1]) % 1000000000) 2021. 2. 22.
[백준 12865] 평범한 배낭 - Python(파이썬) import sys def solution(): for i in range(1, N+1): for j in range(1, K+1): weight = data[i-1][0] value = data[i-1][1] if weight 2021. 2. 22.
[백준 7562] 나이트의 이동 - Python(파이썬) import sys def solution(I, start_x, start_y, end_x, end_y): to_go = [(start_x, start_y)] check[start_x][start_y] = 1 ans = 0 while to_go: temp = [] for toX, toY in to_go: if toX == end_x and toY == end_y: return ans for i in range(8): new_x, new_y = toX + dx[i], toY + dy[i] if 0 2021. 2. 22.
[백준 1697] 숨바꼭질 - Python(파이썬) import sys def solution(N, K): result = [N] check[N] = 1 ans = 0 while result: temp = [] for re in result: if 0 2021. 2. 22.
[백준 1707] 이분 그래프 - Python(파이썬) import sys def solution(): for i in range(1, V+1): if check[i] == 0 and len(data[i]) > 0: keys = [i] check[i] = -1 color = 1 while keys: temp = [] for key in keys: for tp in data[key]: if check[tp] == 0: check[tp] = color temp.append(tp) elif check[tp] != color: return 'NO' color = -color keys = temp return 'YES' K = int(sys.stdin.readline().strip()) for k in range(K): V, E = map(int, sys.stdin... 2021. 2. 22.