Upload files to "백준"
This commit is contained in:
21
백준/10844.py
Normal file
21
백준/10844.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
input = sys.stdin.readline
|
||||||
|
|
||||||
|
N = int(input())
|
||||||
|
|
||||||
|
a = []
|
||||||
|
for i in range(N):
|
||||||
|
a.append(list(map(int, input().split())))
|
||||||
|
|
||||||
|
DP_table = [[0 for _ in range(3)] for _ in range(N+1)]
|
||||||
|
|
||||||
|
DP_table[0][0] = a[0][0]
|
||||||
|
DP_table[0][1] = a[0][1]
|
||||||
|
DP_table[0][2] = a[0][2]
|
||||||
|
|
||||||
|
for i in range(1, N):
|
||||||
|
for j in range(3):
|
||||||
|
DP_table[i][j] = min(DP_table[i-1][(j+1)%3], DP_table[i-1][(j+2)%3]) + a[i][j]
|
||||||
|
|
||||||
|
print(min(DP_table[N-1][0],DP_table[N-1][1],DP_table[N-1][2]))
|
||||||
44
백준/10868.py
Normal file
44
백준/10868.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
input = sys.stdin.readline
|
||||||
|
|
||||||
|
n, m = map(int, input().split())
|
||||||
|
|
||||||
|
height = 0
|
||||||
|
length = n
|
||||||
|
|
||||||
|
while length != 0:
|
||||||
|
length //= 2
|
||||||
|
height += 1
|
||||||
|
|
||||||
|
tree_size = pow(2, height+1)
|
||||||
|
tree_start_index = pow(2, height) - 1
|
||||||
|
tree = [sys.maxsize] * (tree_size+1)
|
||||||
|
|
||||||
|
for i in range(n):
|
||||||
|
tree[tree_start_index+i+1] = int(input())
|
||||||
|
|
||||||
|
temp = n + tree_start_index
|
||||||
|
|
||||||
|
while temp != 1:
|
||||||
|
tree[temp//2] = min(tree[temp//2], tree[temp])
|
||||||
|
temp-=1
|
||||||
|
|
||||||
|
def find_tree(a,b):
|
||||||
|
result = sys.maxsize
|
||||||
|
while a<=b:
|
||||||
|
if (a%2==1):
|
||||||
|
result = min(result, tree[a])
|
||||||
|
a+=1
|
||||||
|
if (b%2==0):
|
||||||
|
result = min(result, tree[b])
|
||||||
|
b-=1
|
||||||
|
a //= 2
|
||||||
|
b //= 2
|
||||||
|
return result
|
||||||
|
|
||||||
|
for _ in range(m):
|
||||||
|
s_i, e_i = map(int, input().split())
|
||||||
|
s_i += tree_start_index
|
||||||
|
e_i += tree_start_index
|
||||||
|
print(find_tree(s_i, e_i))
|
||||||
12
백준/10989.py
Normal file
12
백준/10989.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
N = int(sys.stdin.readline().rstrip())
|
||||||
|
arr=[0] * 10001
|
||||||
|
for i in range(N):
|
||||||
|
temp=int(sys.stdin.readline().rstrip())
|
||||||
|
arr[temp]+=1
|
||||||
|
|
||||||
|
for i in range(10001):
|
||||||
|
if(arr[i]!=0):
|
||||||
|
for j in range(arr[i]):
|
||||||
|
print(i)
|
||||||
21
백준/9465.py
Normal file
21
백준/9465.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import sys
|
||||||
|
import math
|
||||||
|
|
||||||
|
input = sys.stdin.readline
|
||||||
|
|
||||||
|
T = int(input().strip()) # 테스트 케이스 개수
|
||||||
|
for i in range(T):
|
||||||
|
arr = [] # 스티커 가중치
|
||||||
|
total = 0
|
||||||
|
n = int(input().strip()) # 가로 행의 크기
|
||||||
|
arr.append(list(map(int,input().split())))
|
||||||
|
arr.append(list(map(int,input().split())))
|
||||||
|
dp = [[0]*3 for i in range(n)]
|
||||||
|
dp[0][0] = 0
|
||||||
|
dp[0][1] = arr[0][0]
|
||||||
|
dp[0][2] = arr[1][0]
|
||||||
|
for i in range(1, n):
|
||||||
|
dp[i][0] = max(dp[i-1][0], dp[i-1][1], dp[i-1][2])
|
||||||
|
dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + arr[0][i]
|
||||||
|
dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + arr[1][i]
|
||||||
|
print(max(dp[n-1][0], dp[n-1][1], dp[n-1][2]))
|
||||||
37
백준/9663.py
Normal file
37
백준/9663.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
input = sys.stdin.readline
|
||||||
|
|
||||||
|
n = int(input().strip())
|
||||||
|
|
||||||
|
colUsed = [False] * (n)
|
||||||
|
diagUsed = [False] * ((2*n)-1)
|
||||||
|
AntidiagUsed = [False] * ((2*n)-1)
|
||||||
|
|
||||||
|
tot = 0
|
||||||
|
|
||||||
|
def placeQueens(row):
|
||||||
|
global tot
|
||||||
|
|
||||||
|
if (row == n):
|
||||||
|
tot+=1
|
||||||
|
return
|
||||||
|
|
||||||
|
for col in range(n):
|
||||||
|
diagIndex = row - col + n - 1
|
||||||
|
AntiDiagIndex = row + col
|
||||||
|
|
||||||
|
if not colUsed[col] and not diagUsed[diagIndex] and not AntidiagUsed[AntiDiagIndex]:
|
||||||
|
colUsed[col] = True
|
||||||
|
diagUsed[diagIndex] = True
|
||||||
|
AntidiagUsed[AntiDiagIndex] = True
|
||||||
|
|
||||||
|
placeQueens(row + 1)
|
||||||
|
|
||||||
|
colUsed[col] = False
|
||||||
|
diagUsed[diagIndex] = False
|
||||||
|
AntidiagUsed[AntiDiagIndex] = False
|
||||||
|
|
||||||
|
|
||||||
|
placeQueens(0)
|
||||||
|
print(tot)
|
||||||
Reference in New Issue
Block a user