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

1-pu2rile #3

Merged
merged 1 commit into from
Apr 5, 2024
Merged

1-pu2rile #3

merged 1 commit into from
Apr 5, 2024

Conversation

pu2rile
Copy link
Collaborator

@pu2rile pu2rile commented Mar 25, 2024

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

https://www.acmicpc.net/problem/12865

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

1์‹œ๊ฐ„ + ฮฑ

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

๊ฐ€๋ฐฉ ์† ๋ฌผ๊ฑด๋“ค์˜ ์ตœ๋Œ€ ๊ฐ€์น˜ ๊ฐ’์„ ์ฐพ๋Š” ๋ฌธ์ œ

  • ์•Œ๊ณ ๋ฆฌ์ฆ˜
  1. ํ˜„์žฌ ๋ฌผ๊ฑด์ด ๋“ค๊ณ  ์žˆ๋Š” ๋ฌด๊ฒŒ๋ณด๋‹ค ์ž‘๋‹ค๋ฉด [์ด์ „ ๋ฌผ๊ฑด][๊ฐ™์€ ๋ฌด๊ฒŒ] (bag[i-1][j])์ž…๋ ฅ
  2. ํ˜„์žฌ ๋ฌผ๊ฑด์„ ๋„ฃ๊ณ , ๋‚จ์€ ๋ฌด๊ฒŒ์˜ ์ตœ๋Œ“๊ฐ’(bag[i-1][j-w])์„ ์œ„์˜ ํ–‰์—์„œ ๊ฐ€์ ธ์™€์„œ ๋”ํ•จ
  3. ํ˜„์žฌ ๋ฌผ๊ฑด ๋ง๊ณ  ๋‹ค๋ฅธ ๋ฌผ๊ฑด์œผ๋กœ ์ฑ„์šฐ๋Š” ๊ฐ’(bag[i-1][j])์„ ๊ฐ€์ ธ์˜ด
  4. 2์™€ 3 ์ค‘ ๋” ํฐ ๊ฐ’์„ bag[i][j]์— ์ €์žฅ
  5. bag[N][K]๋Š” K๋ฌด๊ฒŒ์ผ ๋•Œ์˜ ์ตœ๋Œ“๊ฐ’์„ ๊ฐ€๋ฆฌํ‚ด
  • ์ˆ˜์‹์œผ๋กœ ํ‘œํ˜„
    bag[i][j] = max(ํ˜„์žฌ ๋ฌผ๊ฑด ๊ฐ€์น˜ + bag[์ด์ „ ๋ฌผ๊ฑด][ํ˜„์žฌ ๊ฐ€๋ฐฉ ๋ฌด๊ฒŒ-ํ˜„์žฌ ๋ฌผ๊ฑด ๋ฌด๊ฒŒ], bag[์ด์ „ ๋ฌผ๊ฑด][ํ˜„์žฌ ๊ฐ€๋ฐฉ ๋ฌด๊ฒŒ])

  • ์—‘์…€ ํ‘œ๋กœ ํ‘œํ˜„

ํ‰๋ฒ”ํ•œ๋ฐฐ๋‚ญ

N, K = map(int, input().split()) #์ž…๋ ฅ์œผ๋กœ ์ฃผ์–ด์ง€๋Š” ์ˆ˜๋Š” ๋ชจ๋‘ ์ •์ˆ˜
item = [[0,0]]
bag = [[0 for _ in range(K + 1)] for _ in range(N + 1)] 
#๊ฐ€๋กœ - ๊ฐ€๋ฐฉ 1~K๊นŒ์ง€์˜ ๋ฌด๊ฒŒ, ์„ธ๋กœ - ๋ฌผ๊ฑด N๊ฐœ์˜ ๊ฐœ์ˆ˜๋กœ ์ด๋ฃจ์–ด์ง„ 2์ฐจ์› ๋ฐฐ์—ด

for _ in range(N): #๋ฌผ๊ฑด์˜ ์ตœ๋Œ€ ๊ฐœ์ˆ˜(N)๋งŒํผ ์ž…๋ ฅ
    item.append(list(map(int, input().split())))


#์•Œ๊ณ ๋ฆฌ์ฆ˜
for i in range(1, N + 1): #๋ฌผ๊ฑด
    for j in range(1, K + 1): #์ตœ๋Œ€ ๋ฌด๊ฒŒ
        w = item[i][0]
        v = item[i][1]

        if j < w:
            bag[i][j] = bag[i - 1][j] #w(eight)๋ณด๋‹ค ์ž‘์œผ๋ฉด ์œ„์˜ ๊ฐ’์„ ๊ทธ๋Œ€๋กœ ๊ฐ€์ ธ์˜ด
        else:
            bag[i][j] = max(v + bag[i - 1][j - w], bag[i - 1][j])
            #bag[i][j] = max(ํ˜„์žฌ ๋ฌผ๊ฑด ๊ฐ€์น˜ + bag[์ด์ „ ๋ฌผ๊ฑด][ํ˜„์žฌ ๊ฐ€๋ฐฉ ๋ฌด๊ฒŒ-ํ˜„์žฌ ๋ฌผ๊ฑด ๋ฌด๊ฒŒ], bag[์ด์ „ ๋ฌผ๊ฑด][ํ˜„์žฌ ๊ฐ€๋ฐฉ ๋ฌด๊ฒŒ])

print(bag[N][K])

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

2024-03-24 + ํ‰๋ฒ”ํ•œ ๋ฐฐ๋‚ญ
@suhyun113
Copy link
Collaborator

๋ฌธ์ œ๊ฐ€ ์ œ ์ˆ˜์ค€์—์„œ ๋„ˆ๋ฌด ์–ด๋ ค์› ์Šต๋‹ˆ๋‹ค. ์—ด์‹ฌํžˆ ์ˆ˜๋„์ฝ”๋“œ ์ž‘์„ฑํ•ด์„œ ์ž˜ ์„ค๋ช…ํ•ด์ฃผ์…จ๋Š”๋ฐ...์ž˜ ์ดํ•ดํ•˜์ง€ ๋ชป ํ–ˆ์Šต๋‹ˆ๋‹ค.

  • ๋ฆฌ์ŠคํŠธ์ปดํ”„๋ฆฌํ—จ์…˜! ์ €๋Š” ๊ตฌ์กฐ๊ฐ€ ์ž˜ ๊ธฐ์–ต๋‚˜์ง€ ์•Š์•„ ์‚ฌ์šฉํ•˜์ง€ ๋ชป ํ–ˆ๋Š”๋ฐ, ์‚ฌ์šฉํ•œ ๊ฒƒ์„ ๋ณด๋‹ˆ ํ•œ ์ค„์— ์ฝ”๋“œ๋ฅผ ๊ฐ„๋‹จํ•˜๊ฒŒ ๊ตฌํ˜„์ด ๊ฐ€๋Šฅํ•œ ๊ฒƒ์ด ์ •๋ง ์ข‹์€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ €๋„ ์ฐธ๊ณ ํ•ด์„œ ๋‹ค์Œ ๋ฒˆ์— ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ๋•Œ๋Š” ์ข€ ๋” ๊ฐ„๋‹จํ•˜๊ฒŒ ๊ตฌํ˜„ํ•ด๋ณด๊ณ  ์‹ถ๋„ค์š”!

  • ์ตœ๋Œ€ํ•œ ์ดํ•ดํ•˜๊ณ  ์‹ถ์–ด์„œ ํ‰๋ฒ”ํ•œ ๋ฐฐ๋‚ญ ๋ฌธ์ œ ํ’€์ด ๊ฐ•์˜๋ฅผ ์ฐพ์•„ ๋“ค์–ด๋ดค์Šต๋‹ˆ๋‹ค. ์™„๋ฒฝํ•œ ์ดํ•ด๋ฅผ ํ•˜๊ธฐ๋Š” ํž˜๋“ค์—ˆ์ง€๋งŒ, ์ œ๊ฐ€ ์ดํ•ดํ•œ ๋ฐ”๋กœ๋Š” ์•„๋ž˜์˜ ์‚ฌ์ง„์ฒ˜๋Ÿผ ์ฝ”๋“œ๊ฐ€ ์ง„ํ–‰๋˜๋Š” ๊ฒƒ ๊ฐ™์•˜์Šต๋‹ˆ๋‹ค. ์ข‹์€ ๋ฌธ์ œ๋ฅผ ํ’€์ดํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ์–ด๋ ค์› ์ง€๋งŒ, ๊นŠ์ด ์‚ฌ๊ณ ํ•ด๋ณผ ์ˆ˜ ์žˆ์–ด์„œ ์ข‹์•˜์Šต๋‹ˆ๋‹ค.

<์ œ๊ฐ€ ์ดํ•ดํ•œ ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค! ํ˜น์‹œ ์ž˜๋ชป ์ดํ•ดํ•œ ๊ฒŒ ์žˆ๋‹ค๋ฉด ์•Œ๋ ค์ฃผ์„ธ์š”>
Screenshot_20240329_022927_Samsung Notes

  • ์ฝ”๋“œ ๊ตฌํ˜„์€ ์–ด๋ ค์› ์ง€๋งŒ, ๋Œ€๋žต์ ์œผ๋กœ ์–ด๋–ค ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ•ด์•ผ ํ•˜๋Š”์ง€๋ฅผ ์ƒ๊ฐํ•ด๋ณผ ์ˆ˜ ์žˆ์—ˆ์–ด์š”!

  • DP๋ผ๋Š” ์œ ํ˜• ์ฒ˜์Œ ๋“ค์–ด๋ณด์•˜๋Š”๋ฐ, ์ด๋Ÿฐ ์œ ํ˜•์˜ ๋ฌธ์ œ๋„ ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ์ฒ˜์Œ ์•Œ๊ฒŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์•„์ง ์•Œ๊ณ ๋ฆฌ์ฆ˜์— ์ต์ˆ™ํ•˜์ง€ ์•Š์•„ ๋ชจ๋ฅด๋Š” ๊ฒƒ์ด ๋งŽ์Šต๋‹ˆ๋‹ค. ๋” ์ข‹์€ ์˜๊ฒฌ์„ ์ค„ ์ˆ˜ ์—†์–ด ์•„์‰ฝ์Šต๋‹ˆ๋‹ค.

  • ์•Œ์•„๋ณด๋‹ˆ ํ˜„์žฌ ์ฝ”๋“œ๋Š” ๋ชจ๋“  ๋ฌผ๊ฑด๊ณผ ๋ฌด๊ฒŒ ์กฐํ•ฉ์— ๋Œ€ํ•ด ๊ฐ’์„ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•ด 2์ฐจ์› ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ํ•„์š”ํ•œ ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฐ ํšจ๊ณผ์ ์ด์ง€๋งŒ, ๋ฌผ๊ฑด์˜ ์ˆ˜(N)์™€ ๋ฐฐ๋‚ญ์˜ ์ตœ๋Œ€ ๋ฌด๊ฒŒ(K)๊ฐ€ ๋งค์šฐ ํด ๊ฒฝ์šฐ ๋งŽ์€ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ์„ ์ค„์ด๊ธฐ ์œ„ํ•ด, ํ˜„์žฌ ๋ฌผ๊ฑด๊ณผ ์ด์ „ ๋ฌผ๊ฑด์˜ ์ •๋ณด๋งŒ์„ ์ €์žฅํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ตœ์ ํ™”ํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
    https://koosaga.com/242
    -> ์ €๋„ ์ž˜์€ ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ, ์ฐธ๊ณ ํ•˜์‹œ๋ฉด ๋„์›€ ๋  ๊ฒƒ ๊ฐ™์•„์„œ ์ฒจ๋ถ€ํ•ฉ๋‹ˆ๋‹ค...

PR์ž‘์„ฑํ•˜์‹ ๋‹ค๊ณ  ์ˆ˜๊ณ  ๋งŽ์œผ์…จ์–ด์š”!

@pu2rile
Copy link
Collaborator Author

pu2rile commented Mar 29, 2024

๋ฌธ์ œ๊ฐ€ ์ œ ์ˆ˜์ค€์—์„œ ๋„ˆ๋ฌด ์–ด๋ ค์› ์Šต๋‹ˆ๋‹ค. ์—ด์‹ฌํžˆ ์ˆ˜๋„์ฝ”๋“œ ์ž‘์„ฑํ•ด์„œ ์ž˜ ์„ค๋ช…ํ•ด์ฃผ์…จ๋Š”๋ฐ...์ž˜ ์ดํ•ดํ•˜์ง€ ๋ชป ํ–ˆ์Šต๋‹ˆ๋‹ค.

  • ๋ฆฌ์ŠคํŠธ์ปดํ”„๋ฆฌํ—จ์…˜! ์ €๋Š” ๊ตฌ์กฐ๊ฐ€ ์ž˜ ๊ธฐ์–ต๋‚˜์ง€ ์•Š์•„ ์‚ฌ์šฉํ•˜์ง€ ๋ชป ํ–ˆ๋Š”๋ฐ, ์‚ฌ์šฉํ•œ ๊ฒƒ์„ ๋ณด๋‹ˆ ํ•œ ์ค„์— ์ฝ”๋“œ๋ฅผ ๊ฐ„๋‹จํ•˜๊ฒŒ ๊ตฌํ˜„์ด ๊ฐ€๋Šฅํ•œ ๊ฒƒ์ด ์ •๋ง ์ข‹์€ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ €๋„ ์ฐธ๊ณ ํ•ด์„œ ๋‹ค์Œ ๋ฒˆ์— ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•  ๋•Œ๋Š” ์ข€ ๋” ๊ฐ„๋‹จํ•˜๊ฒŒ ๊ตฌํ˜„ํ•ด๋ณด๊ณ  ์‹ถ๋„ค์š”!
  • ์ตœ๋Œ€ํ•œ ์ดํ•ดํ•˜๊ณ  ์‹ถ์–ด์„œ ํ‰๋ฒ”ํ•œ ๋ฐฐ๋‚ญ ๋ฌธ์ œ ํ’€์ด ๊ฐ•์˜๋ฅผ ์ฐพ์•„ ๋“ค์–ด๋ดค์Šต๋‹ˆ๋‹ค. ์™„๋ฒฝํ•œ ์ดํ•ด๋ฅผ ํ•˜๊ธฐ๋Š” ํž˜๋“ค์—ˆ์ง€๋งŒ, ์ œ๊ฐ€ ์ดํ•ดํ•œ ๋ฐ”๋กœ๋Š” ์•„๋ž˜์˜ ์‚ฌ์ง„์ฒ˜๋Ÿผ ์ฝ”๋“œ๊ฐ€ ์ง„ํ–‰๋˜๋Š” ๊ฒƒ ๊ฐ™์•˜์Šต๋‹ˆ๋‹ค. ์ข‹์€ ๋ฌธ์ œ๋ฅผ ํ’€์ดํ•ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ์–ด๋ ค์› ์ง€๋งŒ, ๊นŠ์ด ์‚ฌ๊ณ ํ•ด๋ณผ ์ˆ˜ ์žˆ์–ด์„œ ์ข‹์•˜์Šต๋‹ˆ๋‹ค.

<์ œ๊ฐ€ ์ดํ•ดํ•œ ๋ฐฉ์‹์ž…๋‹ˆ๋‹ค! ํ˜น์‹œ ์ž˜๋ชป ์ดํ•ดํ•œ ๊ฒŒ ์žˆ๋‹ค๋ฉด ์•Œ๋ ค์ฃผ์„ธ์š”> Screenshot_20240329_022927_Samsung Notes

  • ์ฝ”๋“œ ๊ตฌํ˜„์€ ์–ด๋ ค์› ์ง€๋งŒ, ๋Œ€๋žต์ ์œผ๋กœ ์–ด๋–ค ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ•ด์•ผ ํ•˜๋Š”์ง€๋ฅผ ์ƒ๊ฐํ•ด๋ณผ ์ˆ˜ ์žˆ์—ˆ์–ด์š”!
  • DP๋ผ๋Š” ์œ ํ˜• ์ฒ˜์Œ ๋“ค์–ด๋ณด์•˜๋Š”๋ฐ, ์ด๋Ÿฐ ์œ ํ˜•์˜ ๋ฌธ์ œ๋„ ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ์ฒ˜์Œ ์•Œ๊ฒŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์•„์ง ์•Œ๊ณ ๋ฆฌ์ฆ˜์— ์ต์ˆ™ํ•˜์ง€ ์•Š์•„ ๋ชจ๋ฅด๋Š” ๊ฒƒ์ด ๋งŽ์Šต๋‹ˆ๋‹ค. ๋” ์ข‹์€ ์˜๊ฒฌ์„ ์ค„ ์ˆ˜ ์—†์–ด ์•„์‰ฝ์Šต๋‹ˆ๋‹ค.
  • ์•Œ์•„๋ณด๋‹ˆ ํ˜„์žฌ ์ฝ”๋“œ๋Š” ๋ชจ๋“  ๋ฌผ๊ฑด๊ณผ ๋ฌด๊ฒŒ ์กฐํ•ฉ์— ๋Œ€ํ•ด ๊ฐ’์„ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•ด 2์ฐจ์› ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” ํ•„์š”ํ•œ ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๋Š” ๋ฐ ํšจ๊ณผ์ ์ด์ง€๋งŒ, ๋ฌผ๊ฑด์˜ ์ˆ˜(N)์™€ ๋ฐฐ๋‚ญ์˜ ์ตœ๋Œ€ ๋ฌด๊ฒŒ(K)๊ฐ€ ๋งค์šฐ ํด ๊ฒฝ์šฐ ๋งŽ์€ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋ฉ”๋ชจ๋ฆฌ ์‚ฌ์šฉ์„ ์ค„์ด๊ธฐ ์œ„ํ•ด, ํ˜„์žฌ ๋ฌผ๊ฑด๊ณผ ์ด์ „ ๋ฌผ๊ฑด์˜ ์ •๋ณด๋งŒ์„ ์ €์žฅํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ตœ์ ํ™”ํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค!
    https://koosaga.com/242
    -> ์ €๋„ ์ž˜์€ ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ, ์ฐธ๊ณ ํ•˜์‹œ๋ฉด ๋„์›€ ๋  ๊ฒƒ ๊ฐ™์•„์„œ ์ฒจ๋ถ€ํ•ฉ๋‹ˆ๋‹ค...

PR์ž‘์„ฑํ•˜์‹ ๋‹ค๊ณ  ์ˆ˜๊ณ  ๋งŽ์œผ์…จ์–ด์š”!

ํ—‰ ์ด๋Ÿฐ ์ •์„ฑ์Šค๋Ÿฌ์šด ์ฝ”๋ฉ˜ํŠธ... ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ใ… ใ… 
์‚ฌ์‹ค ์ด ๋ฌธ์ œ๋Š” ์ œ๊ฐ€ ์—„์„ ํ•œ ๊ฒŒ ์•„๋‹ˆ๋ผ ๋ฆฌ๋“œ๋ฏธ์— ์˜ˆ์‹œ๋กœ ์˜ฌ๋ผ์™€ ์žˆ๋˜ ๊ฑธ ์ฐฉ๊ฐํ•˜๋Š” ๋ฐ”๋žŒ์— ์šธ๋ฉฐ ๊ฒจ์ž๋จน๊ธฐ๋กœ ํ‘ผ ๋ฌธ์ œ๋ž๋‹ˆ๋‹ค... ์ €๋„ ๋„ˆ๋ฌด ์–ด๋ ค์› ์–ด์š” ใ… ใ… 
pr ์ž‘์„ฑ์ด ์ฒ˜์Œ์ด๋ผ ์–ด๋–ป๊ฒŒ ๊ฐ„๊ฒฐํ•˜๊ณ  ์‰ฝ๊ฒŒ ์ˆ˜๋„์ฝ”๋“œ๋ฅผ ์“ธ ์ˆ˜ ์žˆ์„๊นŒ ๊ณ ๋ฏผ์„ ๋งŽ์ด ํ–ˆ๋Š”๋ฐ ์ˆ˜ํ˜„๋‹˜์ด ๊ทธ๋ ค์ฃผ์‹  ๊ทธ๋ฆผ์ด ์ •๋ง ๋ชจ๋“  ๊ฑธ ํ•จ์ถ•ํ•˜๊ณ  ์žˆ๋„ค์š”!! ๋•๋ถ„์— ์ €๋„ ์ดํ•ด๊ฐ€ ๋” ์ž˜ ๋˜๋Š” ๊ฒƒ ๊ฐ™์•„์š”
์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๋ฉด์„œ ๋ฌธ์ œ ํ•ด๊ฒฐ์—๋งŒ ์ง‘์ค‘ํ–ˆ๋˜ ํ„ฐ๋ผ ๋ฉ”๋ชจ๋ฆฌ์— ๋Œ€ํ•ด์„œ๋Š” ์‹ ๊ฒฝ์„ ์“ฐ์ง€ ์•Š์•˜๋Š”๋ฐ ๋ฉ”๋ชจ๋ฆฌ ๋‚ญ๋น„๋ฅผ ์ค„์ผ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์ด ๋˜ ์žˆ์—ˆ๊ตฐ์š”!! ๋ณด๋‚ด ์ฃผ์‹  ๋งํฌ ๊ฐ์‚ฌํžˆ ์ฐธ๊ณ ํ•ด์„œ ๋‹ค์‹œ ๊ณต๋ถ€ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค ๊ฐ์‚ฌํ•ด์š”!!

@pu2rile pu2rile closed this Mar 29, 2024
@pu2rile pu2rile reopened this Mar 29, 2024
Copy link
Member

@oesnuj oesnuj left a comment

Choose a reason for hiding this comment

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

DP๋Š” ์ €๋„ ์ฒ˜์Œ ์ ‘ํ•˜๋Š” ์œ ํ˜•์ธ๋ฐ ๋ญ”์ง€ ๋ชจ๋ฅด๊ณ  ๊ทธ๋ƒฅ ํ’€์–ด๋ดค๋‹ค๊ฐ€ ๊นจ์ง€๊ณ  ๋‚˜์™”๋„ค์š”
์œ„ ๋‘๋ถ„ ์ฝ”๋ฉ˜ํŠธ๋ณด๊ณ  ํ’€์ด๋ฒ•์— ๋Œ€ํ•ด ํž˜๊ฒน๊ฒŒ ์ดํ•ดํ–ˆ์Šต๋‹ˆ๋‹ค. DP์œ ํ˜•์— ๋Œ€ํ•ด ๋งŽ์ด ์ ‘ํ•˜๊ณ  ๋‹ค์‹œ ๋„์ „ํ•ด๋ด์•ผ๊ฒ ๋„ค์š”!!
์ฒซ PR ์ˆ˜๊ณ ํ–ˆ์–ด์š”๐Ÿ‘๐Ÿ‘

@Ghdrn1399
Copy link
Contributor

์ œ๊ฐ€ ํ’€๊ธฐ์—” ๋†’์€ ์ˆ˜์ค€์˜ ๋ฌธ์ œ์—ฌ์„œ ์ฒ˜์Œ์— ์ž˜ ์ดํ•ดํ•˜์ง€ ๋ชปํ–ˆ๋Š”๋ฐ
์ˆ˜ํ˜„๋‹˜ ํ’€์ด๋ž‘ ๋„ํ˜„๋‹˜ ์ˆ˜๋„์ฝ”๋“œ ์ž‘์„ฑํ•ด ์ฃผ์‹ ๊ฑฐ ์—ฌ๋Ÿฌ๋ฒˆ ์ฝ์–ด ๋ณด๊ณ  ์กฐ๊ธˆ์€ ์ดํ•ด ํ•œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
์ €๋„ ๋” ๊ณต๋ถ€ํ•ด์•ผ๊ฒ ๋„ค์š”!!
๋ฆฌ๋ทฐ ๋Šฆ๊ฒŒ ๋‹ฌ์•„์„œ ์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค..^^

if j < w:
bag[i][j] = bag[i - 1][j] #w(eight)๋ณด๋‹ค ์ž‘์œผ๋ฉด ์œ„์˜ ๊ฐ’์„ ๊ทธ๋Œ€๋กœ ๊ฐ€์ ธ์˜ด
else:
bag[i][j] = max(v + bag[i - 1][j - w], bag[i - 1][j])
Copy link
Contributor

Choose a reason for hiding this comment

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

bag[N][K]๊ฐ€ K๋ฌด๊ฒŒ์ผ ๋•Œ์˜ ์ตœ๋Œ“๊ฐ’์„ ๊ฐ€๋ฆฌํ‚ค๋Š” ์ฝ”๋“œ๋ฅผ ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ ๋๋„ค์š”.

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.

4 participants