Skip to content

Latest commit

Β 

History

History
19 lines (13 loc) Β· 777 Bytes

README.md

File metadata and controls

19 lines (13 loc) Β· 777 Bytes

[baekjoon-1149] RGB거리

image

점화식

dp[0][0] = cost[0][0];
dp[0][1] = cost[0][1];
dp[0][2] = cost[0][2];

dp[n][0] = cost[n][0] + Math.min(dp[n-1][1], dp[n-1][2]);
dp[n][1] = cost[n][1] + Math.min(dp[n-1][0], dp[n-1][2]);
dp[n][2] = cost[n][2] + Math.min(dp[n-1][0], dp[n-1][1]);

n λ‹¨κ³„μ—μ„œ λΉ¨κ°•, 초둝, νŒŒλž‘ 쀑 μ–΄λ–€ 색을 μƒ‰μΉ ν•˜λŠλƒμ— λ”°λ₯Έ 정보λ₯Ό λͺ¨λ‘ μ €μž₯해놓아야 ν•œλ‹€. λ˜ν•œ, λ°”λ‘œ μ „ 단계인 n-1 λ‹¨κ³„μ™€λ§Œ 색깔이 λ‹€λ₯΄λ©΄ λœλ‹€. 그에 λŒ€ν•œ μ΅œμ†Ÿκ°’μ„ κ΅¬ν•˜λ©΄ λœλ‹€.

image