Upload files to "백준"
This commit is contained in:
36
백준/14938.py
Normal file
36
백준/14938.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import sys
|
||||
from collections import deque
|
||||
|
||||
input = sys.stdin.readline
|
||||
|
||||
n, m, r = map(int, input().split()) #지역개수, 수색범위, 길의개수
|
||||
graph = [[sys.maxsize for _ in range(n+1)] for _ in range(n+1)]
|
||||
t = list(map(int, input().split()))
|
||||
|
||||
for _ in range(r):
|
||||
a, b, l = map(int, input().split())
|
||||
graph[a-1][b-1] = l
|
||||
graph[b-1][a-1] = l
|
||||
|
||||
for i in range(n):
|
||||
graph[i][i] = 0
|
||||
|
||||
|
||||
# 플로이드-워셜 근본식 그러나 다익스트라보단 구리지만 간단하게
|
||||
for i in range(n):
|
||||
for j in range(n):
|
||||
for k in range(n):
|
||||
if (graph[k][j] > graph[k][i] + graph[i][j]):
|
||||
graph[k][j] = graph[k][i] + graph[i][j]
|
||||
|
||||
result = 0
|
||||
|
||||
for i in range(n):
|
||||
sum_temp = 0
|
||||
for j in range(n):
|
||||
if graph[i][j]<=m:
|
||||
sum_temp += t[j]
|
||||
if sum_temp>result:
|
||||
result = sum_temp
|
||||
|
||||
print(result)
|
||||
31
백준/15286.py
Normal file
31
백준/15286.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
|
||||
input = sys.stdin.readline
|
||||
|
||||
N, K = map(int, input().split())
|
||||
|
||||
items = []
|
||||
|
||||
for _ in range(N):
|
||||
W, V = map(int, input().split())
|
||||
items.append((W, V))
|
||||
|
||||
def promising(i):
|
||||
if i<=K:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
thing = [0] * (K+1)
|
||||
|
||||
for W, V in items:
|
||||
for current_wieght in range(K, W-1 , -1):
|
||||
thing[current_wieght] = max(thing[current_wieght], thing[current_wieght-W]+V)
|
||||
|
||||
result = 0
|
||||
|
||||
for j in thing:
|
||||
if (result < j) :
|
||||
result = j
|
||||
|
||||
print(result)
|
||||
41
백준/15686.py
Normal file
41
백준/15686.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import sys
|
||||
from collections import deque
|
||||
|
||||
input = sys.stdin.readline
|
||||
|
||||
n, m = map(int, input().split())
|
||||
graph = []
|
||||
now_chicken = 0
|
||||
chicken_graph = []
|
||||
house_loc = []
|
||||
for _ in range(n):
|
||||
temp_arr=list(map(int, input().split()))
|
||||
now_chicken+=temp_arr.count(2)
|
||||
graph.append(temp_arr)
|
||||
|
||||
for i in range(n):
|
||||
for j in range(n):
|
||||
if(graph[i][j]==2):
|
||||
chicken_graph.append((i, j))
|
||||
elif(graph[i][j]==1):
|
||||
house_loc.append((i, j))
|
||||
|
||||
def BFS(start, graph):
|
||||
queue = deque([start, 0])
|
||||
visited=set([start])
|
||||
while queue:
|
||||
now_i, now_j, now_distance = queue.popleft()
|
||||
for next_i, next_j in ((now_i+1, now_j), (now_i, now_j+1), (now_i-1, now_j), (now_i, now_j-1)):
|
||||
if 0<=next_i<n and 0<=next_j<n:
|
||||
if (next_i, next_j) not in visited:
|
||||
if graph[next_i][next_j] == 0 or graph[next_i][next_j] == 2:
|
||||
queue.append(next_i, next_j, now_distance+1)
|
||||
visited.add(next_i, next_j)
|
||||
elif graph[next_i][next_j] == 1:
|
||||
return now_distance+1
|
||||
|
||||
|
||||
|
||||
while now_chicken>m:
|
||||
|
||||
|
||||
60
백준/16236.py
Normal file
60
백준/16236.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import sys
|
||||
from collections import deque
|
||||
sys.setrecursionlimit(10**6)
|
||||
|
||||
input = sys.stdin.readline
|
||||
|
||||
n = int(input())
|
||||
|
||||
graph = []
|
||||
nx = [0, -1, 0, 1]
|
||||
ny = [1, 0, -1, 0]
|
||||
|
||||
tot_feed = 0
|
||||
result = 0
|
||||
now_size = 2
|
||||
|
||||
for _ in range(n):
|
||||
graph.append(list(map(int, input().split())))
|
||||
|
||||
for i in range(n):
|
||||
for j in range(n):
|
||||
if graph[i][j] == 9 :
|
||||
now_loc = (i, j)
|
||||
time_loc = (i, j, 0)
|
||||
elif graph[i][j] != 0:
|
||||
tot_feed += 1
|
||||
|
||||
visited = set(now_loc)
|
||||
q = deque()
|
||||
q.append(time_loc)
|
||||
|
||||
while q and tot_feed>0:
|
||||
x, y, time = q.popleft()
|
||||
for i in range(4):
|
||||
dx = x + nx[i]
|
||||
dy = y + ny[i]
|
||||
if 0<=dx<n and 0<=dy<n:
|
||||
if (dx, dy) not in visited:
|
||||
now_value = graph[dx][dy]
|
||||
if now_value== now_size:
|
||||
now_size += 1
|
||||
graph[dx][dy] = 0
|
||||
tot_feed -= 1
|
||||
visited.add((dx, dy))
|
||||
q.append((dx, dy, time+1))
|
||||
elif now_value<=now_size and now_value!=0:
|
||||
graph[dx][dy] = 0
|
||||
tot_feed -= 1
|
||||
visited.add((dx, dy))
|
||||
q.append((dx, dy, time+1))
|
||||
elif now_value == 0:
|
||||
visited.add((dx, dy))
|
||||
q.append((dx, dy, time+1))
|
||||
print(q)
|
||||
|
||||
if q:
|
||||
x,y,time = q.pop()
|
||||
print(time)
|
||||
else:
|
||||
print(0)
|
||||
26
백준/17070.py
Normal file
26
백준/17070.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import sys
|
||||
|
||||
input = sys.stdin.readline
|
||||
|
||||
n = int(input())
|
||||
graph = []
|
||||
for _ in range(n):
|
||||
graph.append(list(map(int, input().split())))
|
||||
|
||||
dp_table = [[[0, 0, 0] for _ in range(n+1)] for _ in range(n+1)] # 0 대각선 1 세로 2 가로
|
||||
|
||||
dp_table[0][1][2] = 1
|
||||
|
||||
for i in range(n):
|
||||
for j in range(n):
|
||||
if (graph[i][j]==1): continue
|
||||
if j>0:
|
||||
dp_table[i][j][2] += dp_table[i][j-1][0] + dp_table[i][j-1][2]
|
||||
if i>0:
|
||||
dp_table[i][j][1] += dp_table[i-1][j][0] + dp_table[i-1][j][1]
|
||||
if i>0 and j>0:
|
||||
if graph[i-1][j] == 0 and graph[i][j-1] == 0:
|
||||
dp_table[i][j][0] += dp_table[i-1][j-1][0] + dp_table[i-1][j-1][1] + dp_table[i-1][j-1][2]
|
||||
|
||||
|
||||
print(dp_table[n-1][n-1][0] + dp_table[n-1][n-1][1] + dp_table[n-1][n-1][2])
|
||||
Reference in New Issue
Block a user