1. Programming/BaekJoon (12) 썸네일형 리스트형 [Baekjoon] 2156번: 포도주 시식(Dynamic Programming) # Baekjoon 2156번: 포도주 시식import sysinput = sys.stdin.readlineN = int(input())cost = []dp = [0] * Nfor i in range(N): cost.append(int(input()))if N == 1: dp[0] = cost[0]elif N == 2: dp[1] = cost[0] + cost[1]else: dp[0] = cost[0] dp[1] = cost[0] + cost[1] dp[2] = max(cost[0] + cost[2], dp[1], cost[1] + cost[2])for i in range(3, N): dp[i] = max(dp[i-2] + cost[i], dp[i-3] + cost[.. [Baekjoon/Python] 1149번: RGB거리(Dynamic Programming) # Baekjoon 1149번: RGB거리import sysinput = sys.stdin.readlineN = int(input())RGB = []dp = [[0]*3 for _ in range(N+1)]for i in range(N): cost = list(map(int, input().split())) RGB.append(cost)dp[0][0] = RGB[0][0]dp[0][1] = RGB[0][1]dp[0][2] = RGB[0][2]for i in range(1, N): dp[i][0] = min(dp[i-1][1], dp[i-1][2]) + RGB[i][0] dp[i][1] = min(dp[i-1][0], dp[i-1][2]) + RGB[i][1] dp[i][2] =.. [Baekjoon/Python] 10026번: 적록색약(BFS) # Baekjoon 10026번: 적록색약import syssys.setrecursionlimit(10**9)from collections import dequeinput = sys.stdin.readlineN = int(input())painting = [[] for _ in range(N)]nor_visited = [[] for _ in range(N)]abnor_visited = [[] for _ in range(N)]normal, abnormal = 0, 0for i in range(N): paint = input().rstrip() for j in paint: painting[i].append(j) nor_visited[i].append(0) ab.. [Baekjoon/Python] 16928번: 뱀과 사다리 게임(BFS) # Baekjoon 16928번: 뱀과 사다리 게임 import sys from collections import deque input = sys.stdin.readline N, M = map(int, input().split()) visited = [0 for _ in range(101)] ladder = [tuple(map(int, input().split())) for _ in range(N)] snake = [tuple(map(int, input().split())) for _ in range(M)] visited_ladder = [None for _ in range(101)] visited_snake = [None for _ in range(101)] for x, y in ladder: visi.. [Baekjoon/Python] 1759번: 암호 만들기(BackTracking) # Baekjoon 1759번: 암호 만들기 import sys input = sys.stdin.readline L, C = map(int, input().split()) code = input().split() code.sort() def DFS(cstr, m): global L if m == C: if len(cstr) == L: count = 0 flag = False for char in cstr: if char in 'aeiou': flag = True else: count += 1 if flag == True and 1 < count: print(cstr) return DFS(cstr + code[m], m+1) DFS(cstr, m+1) DFS("", 0) 이번 문제는 백트래킹 문제이다. 문.. [Baekjoon/Python] 15686번: 치킨 배달(BackTracking) # Baekjoon 15686번: 치킨 배달 import sys from collections import deque from itertools import combinations input = sys.stdin.readline N, M = map(int, input().split()) city = [[] for _ in range(N)] market_info = [] house_info = [] tlst = [] for i in range(N): arr = input().split() for j in range(N): city[i].append(int(arr[j])) if arr[j] == '2': market_info.append((i, j)) elif arr[j] == '1': house_info... [Baekjoon/Python] 14940번: 쉬운 최단거리(BFS) # Baekjoon 14940번: 쉬운 최단거리 import sys from collections import deque input = sys.stdin.readline n, m = map(int, input().split()) arr = [] sol_arr = [[None] * m for _ in range(n)] des_x, des_y = -1, -1 for i in range(n): distance = list(map(int, input().split())) arr.append(distance) for j in range(m): if distance[j] == 2: des_x = j des_y = i elif distance[j] == 0: sol_arr[i][j] = 0 def BFS(): sol.. [Baekjoon/Python] 11724번: 연결 요소의 개수(BFS) # Baekjoon 11724번: 연결 요소의 개수 import sys from collections import deque input = sys.stdin.readline N, M = map(int, input().split()) visited = [None for _ in range(N+1)] graph = [[] for _ in range(N+1)] cnt = 0 for i in range(M): u, v = map(int, input().split()) graph[u].append(v) graph[v].append(u) def BFS(i): global cnt q = deque() q.append(graph[i]) visited[i] = True while q: for v in q.popleft(.. 이전 1 2 다음