목록CodingTest/Baekjoon (27)
모눈종이에 사각사각

🍎 [백준 2294] 동전2 문제 링크 https://www.acmicpc.net/problem/2294 ⚾ 코드 코드 1 n, k = map(int, input().split()) dp = [100001]*100001 coins = [int(input()) for _ in range(n)] coins.sort() for coin in coins: for now in range(1, k+1): if now % coin != 0: dp[now] = min(dp[now], dp[now-coin]+1) else: dp[now] = min(dp[now], now//coin) if dp[k] == 100001: print(-1) else: print(dp[k]) 코드 2 n, k = map(int, input()..

🍎 [백준 11727] 2×n 타일링 2 문제링크 https://www.acmicpc.net/problem/11727 ⚾ 코드 n = int(input()) dp = [0]*(n+1) dp[1] = 1 dp[2] = 3 for i in range(3, n+1): dp[i] = (dp[i-1]+(dp[i-2]*2)) % 10007 print(dp[n]) 🔔 해결 과정 & 깨달은 점 - 다음은 내가 문제를 풀면서 생각한 아이디어 이다. - 각 N은 (이전(N-1)의 경우의 수 + 2*1 타일 추가한 것) + (전전(N-2)의 경우의 수 + 2*2 타일 또는 2*1 타일 2개 추가한 것) 으로 이루어져 있다. - 새로 추가하는 타일 이외의 경우의 수는 이전의 N의 경우의 수에 포함되어 있기 때문에 따로 생각하..

🍎 [백준 1260] DFS와 BFS 문제 링크 ⚾ 코드 from collections import deque # 정점의 개수 N(1 ≤ N ≤ 1,000) # 간선의 개수 M(1 ≤ M ≤ 10,000) # 탐색을 시작할 정점의 번호 V N, M, V = map(int, input().split()) graph = [[] for _ in range(N+1)] visited = [False]*(N+1) for _ in range(M): a, b = map(int, input().split()) # 양방향이기 때문에 리스트 두 군데 다 추가해주어야 한다. graph[a].append(b) graph[b].append(a) # 인접 리스트를 사용할 것이기 때문에 정렬이 필요함. for i in range(N..

🍎 [백준 7569] 토마토 문제 링크 ⚾ 코드 from collections import deque M, N, H = map(int, input().split()) grid = [[] for _ in range(H)] for i in range(H): for _ in range(N): grid[i].append(list(map(int, input().split()))) # grid[i] = i층 # grid[i][x][y] = i층의 x, y좌표 q = deque() dh = [0, 0, 0, 0, 1, -1] dx = [-1, 1, 0, 0, 0, 0] dy = [0, 0, -1, 1, 0, 0] def check_range(h, x, y): if x >= 0 and x = 0 a..

🍎 [백준 7576] 토마토 문제 링크 ⚾ 코드 from collections import deque M, N = map(int, input().split()) grid = [] for _ in range(N): grid.append(list(map(int, input().split()))) q = deque() dx = [-1, 1, 0, 0] dy = [0, 0, -1, 1] def check_range(x, y): if x >= 0 and x = 0 and y < M: return True return False def bfs(): while q: x, y = q.popleft() # 4 방향 살펴보기 for i in range(4): nx = x+dx[i] ny = y+dy[i..

🍎 [백준 2178] 미로 탐색 문제 링크 ⚾ 코드 from collections import deque N, M = map(int, input().split()) grid = [] visited = [[False]*M for _ in range(N)] for _ in range(N): grid.append(list(map(int, input()))) q = deque() dx = [-1, 1, 0, 0] dy = [0, 0, -1, 1] def check_range(x, y): if x >= 0 and x = 0 and y < M: return True return False def bfs(a, b): visited[a][b] = True q.append([a, b]) while q..

🍎 [백준 1012] 유기농 배추 문제 링크 ⚾ 코드 import sys # 재귀 탐색 깊이 늘려주기 sys.setrecursionlimit(100000) input = sys.stdin.readline # 테스트케이스 T = int(input()) answer = [] for _ in range(T): M, N, K = map(int, input().split()) grid = [[0]*(M) for _ in range(N)] visited = [[False]*(M) for _ in range(N)] count = 0 for i in range(K): x, y = map(int, input().split()) grid[y][x] = 1 # 범위 체크 def check_range(x, y): if x >..