본문 바로가기

컴퓨터

백준 17836 - 공주 구출 [bfs] """ 17836 백준 """ from collections import deque H, W, T = map(int, input().split()) arr = [list(map(int, input().split())) for i in range(H)] dirs = [ [0,1], [1,0], [0,-1], [-1,0] ] def bfs(): visited = [[False for i in range(W)] for j in range(H)] visitSword = [[False for i in range(W)] for j in range(H)] q = deque([[0,0,0,0]]) visited[0][0] = True while q: y, x, t, sword = q.popleft() if y == H.. 더보기
삼성 기출 9660 번호 붙이기 """ https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AXCjuQl6J5UDFAX0&categoryId=AXCjuQl6J5UDFAX0&categoryType=CODE """ def dfs(lenArr, arr, idx, tmp, cnt): if len(tmp) == lenArr: return 1 for next in list(filter(lambda x : x != -1 ,[i if str(i) != arr[idx] and str(i) not in tmp else -1 for i in range(1, len(arr)+1)])): cnt += dfs(lenArr, arr, idx + 1, tmp + str(next).. 더보기
curl: (1) Protocol "'http" not supported or disabled in libcurl 데이터 베이스 락 관련해서 토이 프로젝트 중 curl 명령어에서 다음과 같은 에러가 발생했다. 다행히도 원인은 쉽게 찾을 수 있었다. 윈도우에서 커맨드 사용시에는 ' 가 아닌 쌍따옴표 " 를 써야한다. 쌍따옴표로 바꿔서 실행하니 잘 돌아간다. 이제 다시 디비 락을 파헤치러... 더보기
백준 1987 알파벳 - bfs """ 백준 1987 알파벳 """ import sys input = sys.stdin.readline R, C = map(int, input().split()) arr = [input() for _ in range(R)] dir = [[0, 1], [0, -1], [1, 0], [-1, 0]] q = set([(0, 0, arr[0][0])]) answer = 1 while q : y, x, v = q.pop() for d in dir: ny = y + d[0] nx = x + d[1] if 0 더보기
블록이동하기(드론 조종) - bfs def solution(board): H = len(board) W = len(board[0]) moves = [ [0, 1], [0, -1], [1, 0], [-1, 0] ] def bfs(): state = [[[True, True] for _ in range(W)] for __ in range(H)] # 0 가로, 1 세로 q = [[0, 0, 0, 0]] state[0][0][0] = False while q: y, x, curDir, cnt = q.pop(0) if curDir: # 탈출 조건 체크 if x == W - 1 and y + 1 == H - 1: return cnt # 현재 세로라면 이동 or 회전 4가지 # 이동한다면 for move in moves: # 갈 수 있는지 이제부터 확.. 더보기
카카오 외벽 점검 from itertools import permutations def solution(n, weak, dist): answer = 10000000 dist.sort(reverse=True) weak.sort() friendsNum = len(dist) weakLen = len(weak) for i in range(weakLen): weak.append(weak[i]+n) friendPerm = list(permutations(dist, friendsNum)) isFailed = True for i in range(weakLen): currentWeak = weak[i:i+weakLen] for friendComb in friendPerm: curWeakIdx = 0 curFriendIdx = 0 whil.. 더보기
백준 2533 SNS import sys sys.setrecursionlimit(1000000) input = sys.stdin.readline N = int(input()) Tree = [[] for _ in range(N+1)] check = [True for _ in range(N+1)] for _ in range(N-1): u, v=map(int, input().split()) Tree[u].append(v) Tree[v].append(u) dp = [[0,0] for _ in range(N+1)] def dfs(cur): check[cur] = False dp[cur][0] = 0 #포함 x dp[cur][1] = 1 #포함 o for i in Tree[cur]: if check[i]: dfs(i) dp[cur][0.. 더보기
카카오 매출하락 최소화 - 트리 dp 처음 접해본 트리 dp 문제.. https://www.acmicpc.net/problem/2533 2533번: 사회망 서비스(SNS) 첫 번째 줄에는 친구 관계 트리의 정점 개수 N이 주어진다. 단, 2 ≤ N ≤ 1,000,000이며, 각 정점은 1부터 N까지 일련번호로 표현된다. 두 번째 줄부터 N-1개의 줄에는 각 줄마다 친구 관계 트리의 에 www.acmicpc.net 이 문제로 연습한번 하고 바로 들어갔다. import sys def solution(sales, links): def dfs(cur): check[cur] = False dp[cur][0] = 0 # 선택 안할경우 dp[cur][1] = sales[cur-1] # 선택 할경우 for i in tree[cur]: if check[i].. 더보기
백준 5569, 11726 - 출근 경로, 2xn 타일링 [dp] """ 백준 5569 """ w, h = map(int, input().split()) dp = [[[[0 for __ in range(2)] for _ in range(2)] for j in range(w)] for i in range(h)] for i in range(1,w): dp[0][i][1][0] = 1 for i in range(1,h): dp[i][0][1][1] = 1 # 0 0 회전 불가능 가로로 # 1 1 회전 가능 세로로 for i in range(1, h): for j in range(1,w): dp[i][j][0][0] = dp[i][j-1][1][1] dp[i][j][0][1] = dp[i-1][j][1][0] dp[i][j][1][0] = dp[i][j-1][0][0] + d.. 더보기
백준 7576 - 토마토 import sys from collections import deque input = sys.stdin.readline M, N = map(int, input().split()) arr = [list(map(int, input().split())) for _ in range(N)] dir = [ [1,0], [-1,0], [0,1], [0,-1] ] tomatoes = deque([]) for i in range(N): for j in range(M): if arr[i][j] == 1: tomatoes.append([i,j]) while tomatoes: y,x = tomatoes.popleft() nextVal = arr[y][x] + 1 for d in dir: ny = y + d[0] nx = x.. 더보기