-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from AlgoLeadMe/18-alstjr7437
18-alstjr7437
- Loading branch information
Showing
4 changed files
with
64 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# n, m = map(int,input()) | ||
|
||
# num = [ i for i in range(n): int(input())] | ||
|
||
# dp = [[-1e9] * m for _ in range(n+1)] | ||
# for i in range(n): | ||
|
||
import sys | ||
input = sys.stdin.readline | ||
|
||
n, m = map(int, input().split()) | ||
dp1 = [[0]+[-1e9]*m for i in range(n+1)] | ||
dp2 = [[0]+[-1e9]*m for i in range(n+1)] | ||
num = [int(input()) for i in range(n) ] | ||
|
||
for i in range(1, n+1): | ||
for j in range(1, min(m, (i+1)//2)+1): | ||
dp2[i][j]=max(dp1[i-1][j], dp2[i-1][j]) | ||
dp1[i][j]=max(dp1[i-1][j], dp2[i-1][j-1])+num[i-1] | ||
print(max(dp1[n][m], dp2[n][m])) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from heapq import * | ||
import sys | ||
|
||
input = sys.stdin.readline | ||
|
||
v, e = map(int, input().split()) | ||
k = int(input()) | ||
|
||
# 그래프 만들기 | ||
graph = [[] for _ in range(v + 1)] | ||
for _ in range(e): | ||
a, b, c = map(int, input().split()) | ||
graph[a].append((c, b)) | ||
|
||
# 결과 저장할 변수 만들기 | ||
heap = [] | ||
result = [int(1e9)] * (v + 1) | ||
|
||
# k 넣기 | ||
result[k] = 0 | ||
heappush(heap, (0, k)) | ||
|
||
# 다익스트라 돌리기 | ||
while heap: | ||
weight, now = heappop(heap) | ||
# print(weight,now, heap, result) | ||
if result[now] < weight: | ||
continue | ||
for next_weight, next_node in graph[now]: | ||
total_weight = weight + next_weight | ||
if total_weight < result[next_node]: | ||
result[next_node] = total_weight | ||
heappush(heap, (total_weight, next_node)) | ||
|
||
# 결과 출력하기 | ||
for i in range(1, v + 1): | ||
if result[i] == int(1e9): | ||
print("INF") | ||
else: | ||
print(result[i]) |
This file was deleted.
Oops, something went wrong.