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

9-H0ngJu #172

Merged
merged 2 commits into from
May 3, 2024
Merged

9-H0ngJu #172

merged 2 commits into from
May 3, 2024

Conversation

H0ngJu
Copy link
Collaborator

@H0ngJu H0ngJu commented Mar 28, 2024

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

RGB๊ฑฐ๋ฆฌ 2

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

2์‹œ๊ฐ„ 30๋ถ„

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

RGB ๊ฑฐ๋ฆฌ๋ฅผ ๋จผ์ € ํ’€๊ณ  RGB ๊ฑฐ๋ฆฌ 2๋ฅผ ํ’€์—ˆ์Šต๋‹ˆ๋‹ค.

์ผ๋‹จ RGB ๊ฑฐ๋ฆฌ์˜ ๊ตฌํ˜„์€ ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค.

i๋ฒˆ์งธ ์ง‘๊ณผ i+1๋ฒˆ์งธ์˜ ์ƒ‰์ด ๊ฐ™์ง€ ์•Š์œผ๋ฉด์„œ ์ตœ์†Œ ๋น„์šฉ์„ ์„ ํƒํ•˜๊ธฐ๋งŒ ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

๋จผ์ € dp๋Š” 3*N๋ฐฐ์—ด๋กœ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค. ๊ฐ ์—ด์—๋Š” R(0), G(1), B(2)์— ๋Œ€ํ•œ ์ตœ์†Œ ๋น„์šฉ์„ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

1๋ฒˆ ์ง‘๋งŒ 2์ฐจ์› dp[[i]์— ๋จผ์ € ์ €์žฅํ•ด๋‘๊ณ ,
i ๋ฒˆ์งธ ์ง‘์€ i-1๋ฒˆ์งธ์—์„œ ์ƒ‰์น ํ•˜์ง€ ์•Š์€ ๋‘ ์ƒ‰ ์ค‘ ์ตœ์†Œ๋ฅผ ์„ ํƒํ•˜๋Š” ๊ฒƒ์ด๋ฏ€๋กœ,

dp[i][0] = min(dp[i-1][1], dp[i-1][2]) + house[i][0]
# i๋ฒˆ์งธ์— R(0)์„ ์ƒ‰์น ํ•˜๋Š” ๊ฒฝ์šฐ

๋กœ ๊ตฌํ˜„ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

import sys

def input(): return sys.stdin.readline().rstrip()

N = int(input())

house = [[int(x) for x in input().split()] for _ in range(N)]

dp = [[0] * 3 for _ in range(N)]

for i in range(N):
    if i == 0:
        dp[i] = house[i]
    else:
        dp[i][0] = min(dp[i-1][1], dp[i-1][2]) + house[i][0]
        dp[i][1] = min(dp[i-1][0], dp[i-1][2]) + house[i][1] 
        dp[i][2] = min(dp[i-1][0], dp[i-1][1]) + house[i][2] 

print(min(dp[N-1]))

RGB ๊ฑฐ๋ฆฌ 2์—์„œ๋Š” RGB ๊ฑฐ๋ฆฌ๋ฌธ์ œ์™€ ๋˜‘๊ฐ™์ง€๋งŒ '1๋ฒˆ ์ง‘๊ณผ N๋ฒˆ ์ง‘์˜ ์ƒ‰์ด ๋‹ค๋ฅผ ๊ฒƒ'์ด๋ผ๋Š” ์กฐ๊ฑด์ด ์ถ”๊ฐ€๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.
์ฒ˜์Œ์— ํ•ด๋‹น ์กฐ๊ฑด์„ ๋ณด๊ณ  ์ฒ˜์Œ์—” ๋ฐ”๋กœ ์›ํ˜• ์—ฐ๊ฒฐ๋ฆฌ์ŠคํŠธ๋ฅผ ๋– ์˜ฌ๋ ธ์œผ๋‚˜, RGB ๊ฑฐ๋ฆฌ ์ฝ”๋“œ์—์„œ ์กฐ๊ธˆ๋งŒ ์ˆ˜์ •ํ•˜๋ฉด ๋  ๊ฒƒ ๊ฐ™์•„์„œ ์›ํ˜• ์—ฐ๊ฒฐ๋ฆฌ์ŠคํŠธ๋กœ๋Š” ๊ตฌํ˜„ํ•˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.

1๋ฒˆ ์ง‘์˜ ์ƒ‰์„ ์ €์žฅํ•ด๋‘˜ ์ˆ˜๋งŒ ์žˆ๋‹ค๋ฉด N๋ฒˆ ์ง‘์˜ ์ปฌ๋Ÿฌ๋Š” ํ•ด๋‹น ์ปฌ๋Ÿฌ๋ฅผ ์ œ์™ธํ•˜๊ณ  ์ตœ์†Œ ๋น„์šฉ์„ ๊ตฌํ•˜๋ฉด ๋˜๋ฏ€๋กœ
์‰ฝ๊ฒŒ ๊ตฌํ˜„๋ ๊ฑฐ๋ผ ์ƒ๊ฐํ–ˆ์ง€๋งŒ,,

๋ฌธ์ œ๋Š” '1๋ฒˆ ์ง‘์˜ ์ƒ‰์„ ์–ด๋–ป๊ฒŒ ์ €์žฅํ•ด๋‘˜ ๊ฒƒ์ธ๊ฐ€?'์—์„œ ๋ฐœ์ƒํ•˜์˜€์Šต๋‹ˆ๋‹ค.


f_hose ๋ผ๋Š” ๋ฐฐ์—ด์„ ๋งŒ๋“ค์–ด์„œ ์ƒ‰์„ ์ €์žฅํ•ด๋‘๋ฉด, dp ์„ ํƒ๊ณผ์ •์—์„œ ๊ธฐ์กด RGB ๊ฑฐ๋ฆฌ ์ฝ”๋“œ์—์„œ min( dp[i-1][ ], dp[i-1][ ])๋ฅผ ์„ ํƒํ•˜๋Š” ๊ณผ์ •์—์„œ ๊ณ„์†ํ•ด์„œ f_hose์˜ ์œ„์น˜๊ฐ€ ๊ณ„์†ํ•ด์„œ ๋ฐ”๋€Œ๊ธฐ ๋•Œ๋ฌธ์— ์ฒ˜๋ฆฌ๊ฐ€ ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ•˜์˜€์Šต๋‹ˆ๋‹ค.

๊ทธ๋ž˜์„œ ๊ฒฐ๊ตญ ๋‹จ์ˆœํ•˜๊ฒŒ
1๋ฒˆ์ง‘ ์ƒ‰์— ๋”ฐ๋ฅธ ์ฝ”๋“œ๋ฅผ ๊ฐ๊ฐ ๊ตฌํ˜„ํ•˜๊ณ  dp๋„ dp0,dp1,dp2๋กœ ๋‹ค ๋”ฐ๋กœ ๊ตฌํ˜„ํ•˜์—ฌ min์„ ์„ ํƒํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค.

์ฝ”๋“œ๋ณด๊ธฐ
import sys

def input(): return sys.stdin.readline().rstrip()

N = int(input())

house = [[int(x) for x in input().split()] for _ in range(N)]

dp0 = [[0] * 3 for _ in range(N)]
dp1 = [[0] * 3 for _ in range(N)]
dp2 = [[0] * 3 for _ in range(N)]

INF = 1000*1000+1

# 1๋ฒˆ์— (0)์„ ์ƒ‰์น ํ•˜๋Š” ๊ฒฝ์šฐ
for i in range(N):
    if i == 0:
        dp0[i][0] = house[i][0]
        dp0[i][1] = INF
        dp0[i][2] = INF
        #print(i, ":", dp0[i])
    elif i == N-1:
        dp0[i][0] = INF # 0์€ ์ƒ‰์น  ๋ถˆ๊ฐ€์ด๋ฏ€๋กœ
        dp0[i][1] = dp0[i-1][2] + house[i][1] 
        dp0[i][2] = dp0[i-1][1] + house[i][2]
        #print(i,":", dp0[i])
    else: 
        dp0[i][0] = min(dp0[i-1][1], dp0[i-1][2]) + house[i][0]
        dp0[i][1] = min(dp0[i-1][0], dp0[i-1][2]) + house[i][1] 
        dp0[i][2] = min(dp0[i-1][0], dp0[i-1][1]) + house[i][2]
        #print(i,":", dp0[i])

# 1๋ฒˆ์— (1)์„ ์ƒ‰์น ํ•˜๋Š” ๊ฒฝ์šฐ
for i in range(N):
    if i == 0:
        dp1[i][0] = INF
        dp1[i][1] = house[i][1]
        dp1[i][2] = INF
    elif i == N-1:
        dp1[i][0] = dp1[i-1][2] + house[i][0]
        dp1[i][1] = INF
        dp1[i][2] = dp1[i-1][0] + house[i][2]
    else: 
        dp1[i][0] = min(dp1[i-1][1], dp1[i-1][2]) + house[i][0]
        dp1[i][1] = min(dp1[i-1][0], dp1[i-1][2]) + house[i][1] 
        dp1[i][2] = min(dp1[i-1][0], dp1[i-1][1]) + house[i][2]

# 1๋ฒˆ์— (2)์„ ์ƒ‰์น ํ•˜๋Š” ๊ฒฝ์šฐ
for i in range(N):
    if i == 0:
        dp2[i][0] = INF
        dp2[i][1] = INF
        dp2[i][2] = house[i][2]
    elif i == N-1:
        dp2[i][0] = dp2[i-1][1] + house[i][0]
        dp2[i][1] = dp2[i-1][2] + house[i][1] 
        dp2[i][2] = INF 
    else: 
        dp2[i][0] = min(dp2[i-1][1], dp2[i-1][2]) + house[i][0]
        dp2[i][1] = min(dp2[i-1][0], dp2[i-1][2]) + house[i][1] 
        dp2[i][2] = min(dp2[i-1][0], dp2[i-1][1]) + house[i][2]
        

print(min(min(dp0[N-1]), min(dp1[N-1]), min(dp2[N-1])))



๊ทผ๋ฐ ๊ณ„์† ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค๊ฐ€ ๋‚˜์™”์Šต๋‹ˆ๋‹ค ... ์งˆ๋ฌธ๊ฒŒ์‹œํŒ์— ์žˆ๋Š” ๋ฐ˜๋ก€๋„ ํ†ต๊ณผํ•˜๋˜๋ฐ ์™œ ํ‹€๋ฆฐ๊ฑด์ง€ ๋ชจ๋ฅด๊ฒ ๋”๋ผ๊ณ ์š”.. ๐Ÿ˜ญ๐Ÿ˜ญ

๊ทธ๋ž˜์„œ ๋‹ค๋ฅธ ๋ ˆํผ๋Ÿฐ์Šค์˜ ์•„์ด๋””์–ด๋งŒ ์‚ด์ง ์ฐธ๊ณ ํ•ด์„œ RGB ๊ฑฐ๋ฆฌ ๊ธฐ๋ณธ ์ฝ”๋“œ์—์„œ ์กฐ๊ธˆ๋งŒ ์ˆ˜์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค.



์•„์ด๋””์–ด์˜ ํ•ต์‹ฌ์€ '1๋ฒˆ ์ง‘์˜ color๋ฅผ ์ €์žฅํ•ด๋‘๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ, 1๋ฒˆ ์ง‘์˜ color๊ฐ€ dp[N-1]์—์„œ ์„ ํƒ๋˜์ง€ ๋ชปํ•˜๋„๋ก ํ•˜๋Š” ๊ฒƒ'์ž…๋‹ˆ๋‹ค.

  1. 1๋ฒˆ์ง‘์˜ ์ปฌ๋Ÿฌ๋ฅผ ์„ ํƒํ•  ๋ฐ˜๋ณต๋ฌธ ์‹œํ–‰ (0~2๊นŒ์ง€)
  2. dp๋Š” INF๋กœ ์ดˆ๊ธฐํ™”
    1. ๊ธฐ๋ณธ RGB dp ๋กœ์ง ์ˆ˜ํ–‰
  3. dp[N-1][first_hose_color]๋Š” INF๋กœ ๋ณ€๊ฒฝ -> min์—์„œ ์„ ํƒ๋˜์ง€ ์•Š๋„๋ก
  4. cost์—๋Š” ๊ฐ 1๋ฒˆ์ง‘ ์ปฌ๋Ÿฌ์— ๋Œ€ํ•˜์—ฌ ์ตœ์†Ÿ๊ฐ’์„ ์„ ํƒํ•˜์—ฌ ์ €์žฅ

image

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

Copy link
Member

@tgyuuAn tgyuuAn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ™์ฃผ๋‹˜ ์ฝ”๋“œ๊ฐ€ ๊น”๋”ํ•ด์ง„๊ฒŒ ๋ˆˆ์— ๋ณด์—ฌ์„œ ์ข‹๋„ค์š”!

์ด ๋ฌธ์ œ ๋ณด์ž๋งˆ์ž ํŒŒ์ด์ฌ์— ๋„๋‘‘์งˆ ์„ ๋– ์˜ฌ๋ ธ์Šต๋‹ˆ๋‹ค.

์ด ๋ฌธ์ œ๋ž‘ ์ƒ๋‹นํžˆ ์œ ์‚ฌํ•˜๊ณ  ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ๋ ˆ๋ฒจ 3๋ฌธ์ œ๋‹ˆ ํ™์ฃผ๋‹˜ ๊ผญ ํ’€์–ด๋ณด์„ธ์š”!







๋Œ€์ถฉ ํ’€์ด๋ฅผ ์•Œ๊ณ ์žˆ์Œ์—๋„ ์‹œ๊ฐ„์ด ์กฐ๊ธˆ ๊ฑธ๋ ธ์Šต๋‹ˆ๋‹ค.

๋ถ„๋ช… ๋งž๋Š” ์ฝ”๋“ ๋ฐ ์™œ 2%์—์„œ ํ‹€๋ ธ์ง€๋ฅผ ํ•˜๊ณ  ๋ฐ˜๋ก€๋ฅผ ์ฐพ์•„๋ณด๋‹ˆ

5
1 10 100
1 10 100
1 10 100
1 10 100
1 10 100

์˜ ๊ฒฐ๊ณผ๋กœ 122๊ฐ€ ๋‚˜์™€์•ผํ•˜๋Š”๋ฐ ์ž๊พธ 32๋ฅผ ๋ฑ‰๋”๋ผ๊ณ ์š” ...







๊ทธ๋ž˜๋„ ์˜ˆ์ „์— ๋น„์Šทํ•œ ๋ฌธ์ œ๋ฅผ ํ’€์–ด๋ดค๋‹ค๊ณ  30๋ถ„ ์ •๋„ ๋” ํˆฌ์žํ•˜๊ณ  ํ’€ ์ˆ˜ ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค ^^;;;







์‰ฝ์ง€ ์•Š์€ ๋ฌธ์ œ์ธ๋ฐ ๊ณจ๋“œ ๋ฌธ์ œ๋ฅผ ๋„์ „ํ•ด๋ณด์‹œ๋‹ค๋‹ˆ ๋„ˆ๋ฌด ๋Œ€๊ฒฌํ•ด์š”...!

์•ž์œผ๋กœ๋„ ๋น ์ดํŒ…!!!!!!!!!!!!!!

import sys

def input(): return sys.stdin.readline().rstrip()

N = int(input())
costs = [list(map(int,input().split())) for _ in range(N)]
answer = int(1e9)

# ๋๋ถ€๋ถ„ ์ƒ‰์น ํ•˜๊ณ  ์‹œ์ž‘.
for color in range(3):
    DP = [[int(1e9) for _ in range(3)] for _ in range(N+1)]
    DP[0][color] = 0
    
    for idx in range(1,N+1):
        for idx_color in range(3):
            if idx == 1 and idx_color == color: continue
            if idx == N-1 and idx_color == color: continue
            if idx == N and idx_color != color: continue
            
            for diff_color in range(3):
                if idx_color != diff_color:
                    DP[idx][idx_color] = min(DP[idx][idx_color], costs[idx-1][idx_color] + DP[idx-1][diff_color])
    
    answer = min(answer, DP[-1][0], DP[-1][1], DP[-1][2])
    
print(answer)

@miniron-v
Copy link
Member

์ฃผ๋ฌธํ•˜์‹  ๋ฐ˜๋ก€์ž…๋‹ˆ๋‹ค.

elif i == N-1:
        dp0[i][0] = INF # 0์€ ์ƒ‰์น  ๋ถˆ๊ฐ€์ด๋ฏ€๋กœ
        dp0[i][1] = dp0[i-1][2] + house[i][1] 
        dp0[i][2] = dp0[i-1][1] + house[i][2]

์—ฌ๊ธฐ์„œ, i == N-1์ผ ๋•Œ dp0[i][1]์˜ ์ตœ์ ํ•ด๊ฐ€ dp0[i-1][0] + house[i][1]์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ฒซ ์นธ์ด 0๋ฒˆ ์ƒ‰์ด๋‹ˆ N-1๋ฒˆ ์นธ์ด 0์ด ์•„๋‹ˆ์–ด์•ผ ํ•  ๋ฟ, N-2๋ฒˆ์งธ ์นธ์€ 0๋ฒˆ ์ƒ‰์ด ์น ํ•ด์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

@pknujsp
Copy link
Collaborator

pknujsp commented Apr 2, 2024

์˜ˆ์ „์— RGB๊ฑฐ๋ฆฌ1 ํ’€์—ˆ๋˜ ๊ธฐ์–ต๋•Œ๋ฌธ์— 2๋ฒˆ์ด ๊ธˆ๋ฐฉ ํ’€๋ฆด์ค„ ์•Œ์•˜๋Š”๋ฐ ์•„๋‹ˆ๋„ค์š”

n = int(stdin.readline())
houses = [list(map(int, stdin.readline().split())) for _ in range(n)]

for i in range(1, n):
    houses[i][0] += min(houses[i - 1][1], houses[i - 1][2])
    houses[i][1] += min(houses[i - 1][0], houses[i - 1][2])
    houses[i][2] += min(houses[i - 1][0], houses[i - 1][1])

print(min(houses[-1]))

๋งจ ๋ ์ง‘์— ๋Œ€ํ•ด์„œ ์กฐ๊ฑด์ด ์กฐ๊ธˆ๋งŒ ๋‹ฌ๋ผ์กŒ๋Š”๋ฐ๋„ ์ข€ ๊นŒ๋‹ค๋กœ์›Œ ์ง€๋„ค์š”

  • ๋ชจ๋“  ๋น„์šฉ์˜ ํ•ฉ์„ ์ €์žฅํ•  ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ : ์ง‘ ๊ฐœ์ˆ˜์™€ ๊ฐ™์€ ํฌ๊ธฐ๋ฅผ ๊ฐ€์ง€๋Š” costs ๋ฆฌ์ŠคํŠธ๋ฅผ ๋งŒ๋“ค์–ด์„œ ๊ฐ€๋Šฅํ•œ ๋ชจ๋“  ๊ฒฝ์šฐ์˜ ์ตœ์†Œ ํ•ฉ์„ ๊ตฌํ•ด๋‚˜๊ฐ‘๋‹ˆ๋‹ค
    • ๋ฆฌ์ŠคํŠธ ๊ฐ ์›์†Œ์˜ ํฌ๊ธฐ๋Š” 3์ด๊ณ , RGB ๊ฐ๊ฐ์„ ์น ํ•ด๋‚˜๊ฐ„ ๋น„์šฉ ํ•ฉ์„ ์ €์žฅ
  • min_costs์— ์ตœ์†Œ ๋น„์šฉ ํ•ฉ์„ ์ €์žฅ
  • ๋น„์šฉ ๊ณ„์‚ฐ : R, G, B ๊ฐ๊ฐ์˜ ์ƒ‰์ƒ์„ ์ฒซ๋ฒˆ์งธ ์ง‘์— ์ƒ‰์น ํ•˜๋Š” ๊ฑธ๋กœ ์‹œ์ž‘ํ•˜๋Š” ๊ฒฝ์šฐ๋กœ ์‹œ์ž‘ํ•ด์„œ ๋ชจ๋“  ์ง‘์— ์น ํ•ด๋ด…๋‹ˆ๋‹ค
    • ์ฒซ ๋ฒˆ์งธ ์ง‘์— ๋Œ€ํ•ด์„œ๋Š” ์‹œ์ž‘ ์ƒ‰์ƒ์— ๋”ฐ๋ผ ๋น„์šฉ์„ ์„ค์ •
    • ๋‚˜๋จธ์ง€ ์ƒ‰์ƒ์—๋Š” ๋งค์šฐ ํฐ ๊ฐ’์„(INF) ์„ค์ •
    • ๋งŒ์•ฝ R์„ ์น ํ•œ๋‹ค๋ฉด [๋น„์šฉ, INF, INF] ๊ณผ ๊ฐ™์ด ํ•œ๋‹ค
  • ๋‘๋ฒˆ์งธ ์ง‘๋ถ€ํ„ฐ ๋งˆ์ง€๋ง‰ ์ง‘๊นŒ์ง€ ์ธ์ ‘ํ•œ ์ง‘์˜ ์ƒ‰์ƒ๊ณผ ์•ˆ ๊ฒน์น˜๋„๋ก ์น ํ•˜๋Š” ๋น„์šฉ์„ ๊ณ„์‚ฐํ•œ๋‹ค
  • ์ตœ์†Œ ๋น„์šฉ ๊ฐฑ์‹  : min_costs๋ฅผ costs์˜ ๋งˆ์ง€๋ง‰ ์›์†Œ ๋‚ด ์ตœ์†Ÿ๊ฐ’๊ณผ ๋น„๊ตํ•ด์„œ ๊ฐฑ์‹ 
  • ์„ธ ๊ฐ€์ง€ ์ƒ‰์ƒ ์ „๋ถ€์— ๋Œ€ํ•œ ๊ฒฝ์šฐ๋ฅผ ํƒ์ƒ‰ํ•œ ํ›„ min_costs๋ฅผ ์ถœ๋ ฅํ•˜๋ฉด ์ตœ์†Œ ๋น„์šฉ์ด ๋‚˜์˜ต๋‹ˆ๋‹ค
N = int(input())
INF = int(1e7)

arr = [list(map(int, input().split())) for _ in range(N)]
costs = [[0] * 3 for _ in range(N)]
min_cost = INF

for first_color in range(3): 
    
    for color in range(3):
        costs[0][color] = arr[0][color] if color == first_color else INF
            
    for i in range(1, N):
        costs[i][0] = min(costs[i - 1][1], costs[i - 1][2]) + arr[i][0]
        costs[i][1] = min(costs[i - 1][0], costs[i - 1][2]) + arr[i][1]
        costs[i][2] = min(costs[i - 1][0], costs[i - 1][1]) + arr[i][2]

    for color in range(3):
        if color != first_color:
            min_cost = min(min_cost, costs[-1][color])

print(min_cost)

@H0ngJu
Copy link
Collaborator Author

H0ngJu commented Apr 3, 2024

์ฃผ๋ฌธํ•˜์‹  ๋ฐ˜๋ก€์ž…๋‹ˆ๋‹ค.

elif i == N-1:
        dp0[i][0] = INF # 0์€ ์ƒ‰์น  ๋ถˆ๊ฐ€์ด๋ฏ€๋กœ
        dp0[i][1] = dp0[i-1][2] + house[i][1] 
        dp0[i][2] = dp0[i-1][1] + house[i][2]

์—ฌ๊ธฐ์„œ, i == N-1์ผ ๋•Œ dp0[i][1]์˜ ์ตœ์ ํ•ด๊ฐ€ dp0[i-1][0] + house[i][1]์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ฒซ ์นธ์ด 0๋ฒˆ ์ƒ‰์ด๋‹ˆ N-1๋ฒˆ ์นธ์ด 0์ด ์•„๋‹ˆ์–ด์•ผ ํ•  ๋ฟ, N-2๋ฒˆ์งธ ์นธ์€ 0๋ฒˆ ์ƒ‰์ด ์น ํ•ด์งˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋ฏผ์ฒ ์น˜,, ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค (_ _) ๊ทธ๋Ÿฌ๋„ค์š” ... ์Œ... ์–ด ....... ์™œ ์ด๊ฑธ ์ƒ๊ฐ๋ชปํ–ˆ์„๊นŒ ํ—ˆํ—›
๋ฐ˜๋ก€ ์ฐพ์•„์ฃผ์–ด ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‘ฅ ๐Ÿ˜Ž

@MunbinLee MunbinLee merged commit 55dc5e8 into main May 3, 2024
@MunbinLee MunbinLee deleted the 9-H0ngJu branch May 3, 2024 15:37
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.

5 participants