Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20-alstjr7437 #71

Merged
merged 9 commits into from
Apr 10, 2024
28 changes: 28 additions & 0 deletions alstjr7437/BFS/์ˆจ๋ฐ”๊ผญ์งˆ.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from collections import deque

n, k = map(int, input().split())

result = [0] * 100001
result[n] = 1

queue = deque()
queue.append(n)

while queue:
now = queue.popleft()
if now == k:
break
# -1 ๋กœ์ง
if now - 1 >= 0 and result[now-1] == 0 :
queue.append(now-1)
result[now-1] = result[now] + 1
# +1 ๋กœ์ง
if now + 1 < len(result) and result[now+1] == 0:
queue.append(now+1)
result[now+1] = result[now] + 1
# *2 ๋กœ์ง
if now * 2 < len(result) and result[now * 2] == 0:
queue.append(now*2)
result[now*2] = result[now] + 1

print(result[k] - 1)
21 changes: 21 additions & 0 deletions alstjr7437/DP/๊ตฌ๊ฐ„-๋‚˜๋ˆ„๊ธฐ.py
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]))

6 changes: 5 additions & 1 deletion alstjr7437/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
| 13์ฐจ์‹œ | 2024.02.29 | DP | <a href="https://www.acmicpc.net/problem/10844">์‰ฌ์šด ๊ณ„๋‹จ ์ˆ˜</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/42 |
| 14์ฐจ์‹œ | 2024.03.03 | ๋ธŒ๋ฃจํŠธํฌ์Šค | <a href="https://www.acmicpc.net/problem/18111">๋งˆ์ธํฌ๋ž˜ํ”„ํŠธ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/48 |
| 15์ฐจ์‹œ | 2024.03.09 | ์šฐ์„ ์ˆœ์œ„ ํ | <a href="https://www.acmicpc.net/problem/13975">ํŒŒ์ผ ํ•ฉ์น˜๊ธฐ3</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/53 |
| 16์ฐจ์‹œ | 2024.03.13 | ์ •๋ ฌ | <a href="https://www.acmicpc.net/problem/2170">์„  ๊ธ‹๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/57 |
| 16์ฐจ์‹œ | 2024.03.13 | ์ •๋ ฌ | <a href="https://www.acmicpc.net/problem/2170">์„  ๊ธ‹๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/57 |
| 17์ฐจ์‹œ | 2024.03.16 | DP | <a href="https://www.acmicpc.net/problem/2228">๊ตฌ๊ฐ„ ๋‚˜๋ˆ„๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/61 |
| 18์ฐจ์‹œ | 2024.03.23 | ๋‹ค์ต์ŠคํŠธ๋ผ | <a href="https://www.acmicpc.net/problem/1753">์ตœ๋‹จ ๊ฒฝ๋กœ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/66 |
| 19์ฐจ์‹œ | 2024.03.27 | ๋ฌธ์ž์—ด | <a href="https://www.acmicpc.net/problem/5525">IOIOI</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/67 |
| 20์ฐจ์‹œ | 2024.04.03 | BFS | <a href="https://www.acmicpc.net/problem/1697">์ˆจ๋ฐ”๊ผญ์งˆ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/70 |
41 changes: 41 additions & 0 deletions alstjr7437/๊ตฌํ˜„/IOIOI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
let n = Int(readLine()!)!
let m = Int(readLine()!)!

let s = readLine()!.map{$0}

var result = 0
var cur = 0
var count = 0

while cur < m-2{
if String(s[cur...cur + 2]) == "IOI"{
count += 1
cur += 2
if count == n{
result += 1
count -= 1
}
} else {
count = 0
cur += 1
}
}

print(result)


"""
50์ ์งœ๋ฆฌ ์ฝ”๋“œ

var p = "I"
for _ in 0 ..< n{
p += "OI"
}

for i in 0..<m-p.count+1{
if String(s[i..<i+p.count]) == p{
result += 1
}
}
"""

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])
3 changes: 0 additions & 3 deletions alstjr7437/์ •๋ ฌ/tempCodeRunnerFile.py

This file was deleted.

Loading