본문 바로가기

분류 전체보기

(402)
[백준 2517번] 달리기 (Python3) import sys input = sys.stdin.readline def updatefen(i): while i
[백준 4013번] ATM (Python3) import sys,collections input = sys.stdin.readline sys.setrecursionlimit(10**6) def BFS(): result = 0; pre = [0]*C while dq: now = dq.popleft() if sccrest[now]: result = max(result,pre[now]+scc[now]) for next in sccgraph[now]: indegree[next] -= 1 pre[next] = max(pre[next],pre[now]+scc[now]) if not indegree[next]: dq.append(next) return result def DFS(now): global id,start visited[now] = nowid = i..
[백준 1777번] 순열복원 (Python3) def updatefen(i): while is: return find(x,i+(1
[백준 1866번] 택배 (Python3) N = int(input()) data = sorted(map(int,input().split())) truck,heli = map(int,input().split()) prefix = [0] for i in range(N): prefix.append(prefix[-1]+data[i]*truck) DP = prefix[:] for end in range(1,N+1): for start in range(1,end+1): mid = (start+end)//2; r = (start+end)%2 DP[end] = min(DP[end],DP[start-1]+heli+prefix[end]-prefix[mid]-prefix[mid-1]+prefix[start-1]-r*data[mid-1]*truck) print(DP..
[백준 10220번] Self Representing Seq (Python3) import sys input = sys.stdin.readline def DFS(now,SUM): global result for i in range(N): if cnt[i]==seq[i]: continue if cnt[i]>seq[i] and iN or now==N: return cnt[i] += 1 seq[now] = i DFS(now+1,SUM+i) cnt[i] -= 1 seq[now] = -1 if now==N: result += 1 for _ in range(int(input())): N = int(input()) if N6인 경우에 대해서 self representing seq는 유일한 수열을 갖는다고 한다. 따라서 다음과 같은 코드도 통과 가능하다. for _ in range(int(inp..
[백준 1280번] 나무 심기 (Python3) import sys input = sys.stdin.readline def updatefen(i,v,fen): while i
[백준 1185번] 유럽여행 (Python3) import sys input = sys.stdin.readline from heapq import * def findparent(x): if parent[x]!=x: parent[x] = findparent(parent[x]) return parent[x] N,M = map(int,input().split()) cost = [1e6]+[int(input()) for i in range(N)] hq = []; parent = [i for i in range(N+1)] for _ in range(M): a,b,c = map(int,input().split()) heappush(hq,(c*2+cost[a]+cost[b],a,b)) result = 0 while hq: c,a,b = heappop(hq) if..
[백준 12920번] 평범한 배낭 2 (Python3) import sys input = sys.stdin.readline N,M = map(int,input().split()) stuff = [] for _ in range(N): w,c,k = map(int,input().split()) l = len(bin(k))-3; k -= (1