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-SeongHoonC #75

Merged
merged 5 commits into from
Apr 17, 2024
Merged

20-SeongHoonC #75

merged 5 commits into from
Apr 17, 2024

Conversation

SeongHoonC
Copy link
Collaborator

πŸ”— 문제 링크

μ•±

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

1μ‹œκ°„ 30λΆ„

✨ μˆ˜λ„ μ½”λ“œ

ν‰λ²”ν•œ λ°°λ‚­κ³Ό λΉ„μŠ·ν•œ λ¬Έμ œμ΄λ‹€.
κ·ΈλŸ¬λ‚˜ μ—΄ 기쀀을 Byte 둜 μž‘μ•„μ„œ μ˜€λž˜κ±Έλ Έλ‹€.

5 60
30 10 20 35 40
3 0 3 5 4

  1. 5개의 앱이 행이 되고 λΉ„μš©μ˜ MAX κ°’(10000) 을 μ—΄λ‘œ μž‘λŠ”λ‹€.
  2. dp[i][j] λŠ” ν•΄λ‹Ή μ•„μ΄ν…œ i κΉŒμ§€ λ„£μ—ˆμ„ λ•Œ j λΉ„μš©μœΌλ‘œ 얻을 수 μžˆλŠ” μ΅œλŒ€ μš©λŸ‰μ„ λ„£μ–΄μ•Όν•œλ‹€.
    3-1. 앱을 더 μ’…λ£Œν•  수 μ—†λ‹€λ©΄ 이전에 d[i-1][j] λ₯Ό 담아놓은 것 κ·ΈλŒ€λ‘œ λ‹΄λŠ”λ‹€.
    3-2. 앱을 더 μ’…λ£Œν•  수 μžˆλ‹€λ©΄ 이전에 ν˜„μž¬ λΉ„μš© - μ•±μ˜ λΉ„μš© μ΅œμ κ°’μ— μš©λŸ‰μ„ λ”ν•œλ‹€.

λͺ©ν‘œ μš©λŸ‰μ„ λ„˜κ²Όλ‹€λ©΄ μ •λ‹΅ μ΅œμ†Œκ°’μ„ μ—…λ°μ΄νŠΈν•œλ‹€.

image
const val MAX_COST = 10_000
fun main() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val (n, m) = br.readLine().split(" ").map { it.toInt() }

    // λΉ„μš©μ˜ μ΅œλŒ€λŠ” 100 * 100 이닀
    val dp = Array(n + 1) { Array(MAX_COST + 1) { 0 } }
    val bytes = listOf(0) + br.readLine().split(" ").map { it.toInt() }
    val cost = listOf(0) + br.readLine().split(" ").map { it.toInt() }

    var minCost = Int.MAX_VALUE
    for (i in 1..n) {
        for (j in 0..MAX_COST) {
            // 담을 수 μ—†λ‹€λ©΄ 이전에 i-1 κΉŒμ§€ 담아놓은 것 κ·ΈλŒ€λ‘œ
            if (j - cost[i] < 0) {
                dp[i][j] = dp[i - 1][j]
                continue
            }
            // 담을 수 μžˆλ‹€λ©΄ ν˜„μž¬ λΉ„μš© - μ•±μ˜ λΉ„μš© μ΅œμ κ°’μ— 얻을 수 μžˆλŠ” μš©λŸ‰ λ”ν•˜κΈ°
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - cost[i]] + bytes[i])

            // λͺ©ν‘œ μš©λŸ‰μ„ λ„˜μ—ˆλ‹€λ©΄ μ •λ‹΅ μ΅œμ†Œκ°’ μ—…λ°μ΄νŠΈ
            if (dp[i][j] >= m) {
                minCost = min(minCost, j)
            }
        }
    }
    println(minCost)
}

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

@alstjr7437
Copy link
Member

머리λ₯Ό λ„ˆλ¬΄ 많이 μ¨μ„œ κ·ΈλŸ°κ°€ 사싀 μ²˜μŒμ— λ¬Έμ œκ°€ μ–΄λ–»κ²Œ λŒμ•„κ°€λŠ”μ§€ λͺ°λΌμ„œ 인터넷을 μ•½κ°„ 보고
μ ν™”μ‹μ—μ„œ μ§„ν–‰ν•˜λ©΄μ„œ 닡을 λ„£λŠ” λΆ€λΆ„μ—μ„œ κ²°κ΅­ 인터넷 μ°Έκ³ ν•˜κ³  ν’€μ—ˆλ„€μš”..

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

A = [0] + list(map(int, input().split()))
C = [0] + list(map(int, input().split()))

dp = [[0 for _ in range(sum(C) + 1)] for _ in range(n + 1)]
result = sum(C)

for i in range(1, n+1):
    ci, Ai = C[i], A[i]
    for j in range(sum(C) + 1):
        dp[i][j] = dp[i-1][j]
    for j in range(ci, sum(C) + 1):
        dp[i][j] = max(dp[i-1][j-ci] + Ai, dp[i][j])
        if dp[i][j] >= m:
            result = min(result, j)

print(result)

@SeongHoonC SeongHoonC merged commit 69fd872 into main Apr 17, 2024
4 checks passed
@SeongHoonC SeongHoonC deleted the 20-SeongHoonC branch April 17, 2024 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants