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

17-alstjr7437 #61

Merged
merged 4 commits into from
Apr 8, 2024
Merged

17-alstjr7437 #61

merged 4 commits into from
Apr 8, 2024

Conversation

alstjr7437
Copy link
Member

@alstjr7437 alstjr7437 commented Mar 16, 2024

πŸ”— 문제 링크

ꡬ간 λ‚˜λˆ„κΈ°

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

1μ‹œκ°„(30λΆ„ μ§œλ³΄λ‹€κ°€ 인터넷에 아이디어 μ°Έκ³ ..)

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

일단 μ €λ²ˆ PRμ—μ„œ λ‚˜μ˜¨ μ„±ν›ˆλ‹˜μ˜ λˆ„μ ν•© λ¬Έμ œκ°€ μžˆμ–΄μ„œ 이 문제λ₯Ό λ“€κ³  μ™”λŠ”λ° λ„μ €νžˆ DPλ‘œλŠ” 생각이 μ•ˆλ‚˜λ”λΌκ΅¬μš”...
κ·Έλž˜μ„œ 인터넷을 쑰금 μ°Έκ³ ν•΄μ„œ ν’€μ—ˆμŠ΅λ‹ˆλ‹€.




일단 μ•„μ΄λ””μ–΄λŠ” λ‘κ°œμ˜ DP 배열을 λ§Œλ“­λ‹ˆλ‹€!!!
κ·Έλ ‡κ²Œ λ§Œλ“  λ‘κ°œμ˜ 배열은
1 -> ν•΄λ‹Ή indexλ₯Ό ν¬ν•¨ν•œ λ°°μ—΄
2 -> ν•΄λ‹Ή indexλ₯Ό ν¬ν•¨ν•˜μ§€ μ•Šμ€ λ°°μ—΄




예λ₯Ό λ“€μ–΄
-1, 3, 1, 2, 4 -1 이 있으면

image

μœ„ 사진과 같이
con[i][1]μ—λŠ” ν˜„μž¬κΉŒμ§€ 전체 λˆ„μ ν•©μ΄ λ“€μ–΄κ°€κ³ 
notcon[i][1]μ—λŠ” ν•΄λ‹Ή 인덱슀(i)λ₯Ό μ œμ™Έν•œ λˆ„μ ν•©μ΄ λ“€μ–΄κ°‘λ‹ˆλ‹€.




그리고 2개의 m개의 ꡬ간이 μžˆμ–΄μ•Όν•˜λ‹ˆκΉŒ μ˜ˆμ œμ—λŠ” 2둜 λ“€μ–΄μ™€μ„œ
dp1[i][2]μ—λŠ” dp1[i-1][j]κ³Ό dp2[i-1][j-1] 의 λ‘˜ 쀑 큰 값에 ν˜„μž¬ 인덱슀의 값이 λ“€μ–΄κ°‘λ‹ˆλ‹€.
dp2[i][2]μ—λŠ” dp1[i-1][j]와 dp2[i-1][j] λΉ„κ΅ν•΄μ„œ λ“€μ–΄κ°€κ²Œ λ©λ‹ˆλ‹€.




저도 이뢀뢄을 κΈ€λ‘œλ§Œ 보면 μ–΄λ €μ› μ—ˆλŠ”λ°




3λ²ˆλΆ€ν„° 예λ₯Ό λ“€λ©΄
con -> max(dp2(-1), dp1(f)), + 1(i)이 선택
con -> max(dp2(3), dp1(0)), + 2(i)κ°€ 선택


image

μ΄λ ‡κ²Œ μ­‰ λ‚΄λ €κ°€μ„œ
dp1, dp2의 n,mμΈλ±μŠ€μ€‘ 큰 값을 좜λ ₯ν–ˆμŠ΅λ‹ˆλ‹€.





μ½”λ“œ

import sys
input = sys.stdin.readline

n, m = map(int, input().split())
dp1 = [[0]+[-1e9]*m for i in range(n+1)]
dp2 = [[0]+[-1e9]*m for i in range(n+1)]
num = [int(input()) for i in range(n) ]

for i in range(1, n+1):
    for j in range(1, min(m, (i+1)//2)+1):
        dp2[i][j]=max(dp1[i-1][j], dp2[i-1][j])
        dp1[i][j]=max(dp1[i-1][j], dp2[i-1][j-1])+num[i-1]
print(max(dp1[n][m], dp2[n][m]))

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

μ°Έκ³  λΈ”λ‘œκ·Έ

dpμ—μ„œ 점화식을 μ„Έμš°λŠ”κ²Œ 아직 μ°Έ μ–΄λ ΅λ‹€κ³  λŠλ‚Œ μ–΄λ–€ μ—°κ΄€μ„±μœΌλ‘œ 짓냐 뢀뢄이 아직 많이 λΆ€μ‘±...

@SeongHoonC
Copy link
Collaborator

λΈ”λ‘œκ·Έ λ³΄λ©΄μ„œ μ΄ν•΄ν•΄λ΄€μŠ΅λ‹ˆλ‹€.. μ € μ‚¬λžŒ μ²œμž¬μΈκ°€μš”?

@alstjr7437 alstjr7437 merged commit 12c7b57 into main Apr 8, 2024
@alstjr7437 alstjr7437 deleted the 17-alstjr7437 branch April 8, 2024 04:57
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