baekjoon 20260214
This commit is contained in:
parent
1dd473dccc
commit
fdd1a53d87
1
code_study/Baekjoon/python/14924.py
Normal file
1
code_study/Baekjoon/python/14924.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
print((lambda x : (x[2] // (2*x[0]))*x[1])(list(map(int, input().split()))))
|
||||||
29
code_study/Baekjoon/python/2342_1.py
Normal file
29
code_study/Baekjoon/python/2342_1.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import sys
|
||||||
|
sys.setrecursionlimit(10**6)
|
||||||
|
|
||||||
|
force = [
|
||||||
|
[1,2,2,2,2],
|
||||||
|
[2,1,3,4,3],
|
||||||
|
[2,3,1,3,4],
|
||||||
|
[2,4,3,1,3],
|
||||||
|
[2,3,4,3,1]
|
||||||
|
]
|
||||||
|
|
||||||
|
seq = list(map(int, input().split()))
|
||||||
|
n = len(seq)
|
||||||
|
inf = float("inf")
|
||||||
|
dp = [[[inf]*5 for _ in range(5)] for _ in range(n)]
|
||||||
|
|
||||||
|
def dfs(L, R, step) :
|
||||||
|
target = seq[step]
|
||||||
|
if target == 0 :
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if dp[step][L][R] == inf :
|
||||||
|
moveLeft = dfs(target, R, step+1) + force[L][target]
|
||||||
|
moveRight = dfs(L, target, step+1) + force[R][target]
|
||||||
|
dp[step][L][R] = min([moveLeft, moveRight])
|
||||||
|
|
||||||
|
return dp[step][L][R]
|
||||||
|
|
||||||
|
print(dfs(0,0,0))
|
||||||
34
code_study/Baekjoon/python/2342_2.py
Normal file
34
code_study/Baekjoon/python/2342_2.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
force = [
|
||||||
|
[1,2,2,2,2],
|
||||||
|
[2,1,3,4,3],
|
||||||
|
[2,3,1,3,4],
|
||||||
|
[2,4,3,1,3],
|
||||||
|
[2,3,4,3,1]
|
||||||
|
]
|
||||||
|
|
||||||
|
seq = list(map(int, input().split()))
|
||||||
|
n = len(seq)
|
||||||
|
inf = float("inf")
|
||||||
|
dp = [[[inf]*5 for _ in range(5)] for _ in range(2)]
|
||||||
|
for i in range(5) :
|
||||||
|
for j in range(5) :
|
||||||
|
dp[1][i][j] = 0
|
||||||
|
|
||||||
|
cur_idx = 0
|
||||||
|
nxt_idx = 1
|
||||||
|
|
||||||
|
for step in range(n-1,-1, -1) :
|
||||||
|
target = seq[step]
|
||||||
|
if target == 0 :
|
||||||
|
continue
|
||||||
|
|
||||||
|
for l in range(5) :
|
||||||
|
for r in range(5) :
|
||||||
|
moveLeft = dp[nxt_idx][target][r] + force[l][target]
|
||||||
|
moveRight = dp[nxt_idx][l][target] + force[r][target]
|
||||||
|
dp[cur_idx][l][r] = min(moveLeft, moveRight)
|
||||||
|
|
||||||
|
cur_idx = 1 if cur_idx == 0 else 0
|
||||||
|
nxt_idx = 1 if cur_idx == 0 else 0
|
||||||
|
|
||||||
|
print(dp[nxt_idx][0][0])
|
||||||
Loading…
x
Reference in New Issue
Block a user