17144 미세먼지 안녕
·
백준
import sys input = sys.stdin.readline R, C, T = map(int, input().split()) room = [list(map(int, input().split())) for _ in range(R)]#방 정보 입력받기 roomnext = [[0 for _ in range(C)] for _ in range(R)]#확산된 미세먼지 임시 저장 way = [(-1, 0), (0, 1), (1, 0), (0, -1)]#각 칸에서 이동할 수 있는 네 방향 cleaner = [] # 0번이 위쪽 1번이 아래쪽 for i in range(0, R): # 청정기 위치 찾기 for j in range(0, C): if room[i][j] == -1: cleaner.append(i) d..
15686 치킨 배달
·
백준
from itertools import combinations N,M=map(int,input().split()) city=[list(map(int,input().split())) for _ in range(N)] house=[] chicken=[] for i in range(0,N): for j in range(0,N): if city[i][j]==1: house.append((i,j)) if city[i][j]==2: chicken.append((i,j)) res=10000 for i in list(combinations(chicken,M)): citydist=0 for j in house: hometochiken=1000 for k in i: hometochiken=min(hometochiken,a..
11053 가장 긴 증가하는 부분 수열
·
백준
length=int(input()) seq=list(map(int,input().split())) dp=[0 for i in range(0,length)] for i in range(0,len(seq)): if dp[i]==0: dp[i]=1 for j in range(0,i): if seq[j]
1932 정수 삼각형
·
백준
h=int(input()) level=[[0]]#삼각형을 저장하는 리스트 levelsum=[[0]]#삼각형의 각 층의 노드마다 해당 노드까지의 숫자의 합 중 가장 큰 값을 저장하는 리스트 for i in range(h):#삼각형 입력받기 level.append(list(map(int,input().split()))) maxsum=-1 for i in range(1,len(level)): tmpsum=[] for j in range(0,len(level[i])): cur=level[i][j] if j==0:#삼각형의 가장자리 maxprev=levelsum[i-1][j] elif j==len(level[i])-1:#삼각형의 가장자리 maxprev=levelsum[i-1][j-1] else:#이전 층에서 해당..
1918 후위표기식
·
백준
notation=list(input()) stack=[] cnt=-1 conti=False for i in notation: cnt=cnt+1 if conti: conti=False continue if i=='+' or i=='-': while True: if not stack: stack.append(i) break item=stack.pop() if item!='(': print(item,end='') else: stack.append(item) stack.append(i) break elif i=='*' or i=='/': while True: if not stack: stack.append(i) break item=stack.pop() if item=='*' or item=='/': print(..
1238 파티
·
백준
import heapq N,M,X=map(int,input().split()) graph=[[] for _ in range(M+1)]#간선들을 저장 for i in range(0,M): start,end,cost=map(int,input().split()) graph[start].append((end,cost)) def dijkstra(start): q=[] #distance의 인덱스 번호:마을 번호 - start지점에서 해당 마을까지 가는데 드는 비용이 기록되어 있음 distance=[int(1e9)]*(M+1)#방문하지 않은 마을은 초기에 무한으로 설정 heapq.heappush(q,(0,start))# distance[start]=0#start마을까지 가는데 드는 비용은 0원 while q: #이전..
1991 트리 순회
·
백준
class Node: def __init__(self,data): self.data=data self.right=None self.left=None class BinaryTree(): def __init__(self): self.root=None h=int(input()) tree=BinaryTree() dictionary={} for i in range(0,h): n,l,r=input().split() node=Node(n) node.left=l node.right=r dictionary[n]=node tree.root=dictionary['A'] def preorder(node): if node.data=='.': return print(node.data,end='') if node.left!='.'..
1049:rgb거리
·
백준
n=int(input()) d=[[0,0,0]] rgb=[[0,0,0]] for i in range(1,n+1): rgb.append(list(map(int,input().split()))) for i in range(1,n+1):#처음에 선택한 색깔의 경우에 따라 비용을 구함 d.append([min(d[i-1][1],d[i-1][2])+rgb[i][0], min(d[i-1][0],d[i-1][2])+rgb[i][1], min(d[i-1][0],d[i-1][1])+rgb[i][2]]) print(min(d[n][0],d[n][1],d[n][2]))#세 경우중 가장 작은 경우 출력 동적 계획법으로 풀 수 있는 문제이다. 양 옆의 집과 겹치지 않는 색으로 칠해야 하기 때문에 맨 처음에 최소 비용으로 칠한다..
oksdfn
'백준' 카테고리의 글 목록