Skip to content

Latest commit

Β 

History

History

P12865

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Β 
Β 
Β 
Β 
Β 
Β 

[baekjoon-12865] ν‰λ²”ν•œ λ°°λ‚­

image

점화식

2차원 λ°°μ—΄

for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= K; j++) {
        if (j < W[i]) dp[i][j] = dp[i-1][j];
        else dp[i][j] = Math.max(dp[i-1][j], V[i] + dp[i-1][j-W[i]]);
    }
}

1차원 λ°°μ—΄

for (int i = 1; i <= N; i++) {
    for (int j = K; j >= W[i]; j--) {
        dp[j] = Math.max(dp[j], V[i] + dp[j-W[i]]);
    }
}

일차원 λ°°μ—΄λ‘œ ν’€μ΄ν•˜λ˜, 이전 λ‹¨κ³„μ˜ value 값을 μ‚¬μš©ν•˜κΈ° μœ„ν•΄μ„œλŠ” λ’€μ—μ„œλΆ€ν„° νƒμƒ‰ν•˜λ©΄ λœλ‹€.

image