-
Notifications
You must be signed in to change notification settings - Fork 1
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-wkdghdwns199 #68
17-wkdghdwns199 #68
Conversation
@alstjr7437 λΉ‘μΈλλΌκ΅¬μ.. γ γ γ μ¬κ·λ₯Ό μν΄λ λλκ°μ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3μ°¨μ dp λ€μ λ¬Έμ ν¨μ μ΄ν΄νλκ² λ무 μ΄λ €μ μ΅λλ€ γ γ
μ¬κ·λ λ§λλ° νΉμ ν μλ₯Ό ꡬνλ μμΈκ° νλ©΄μ κΉκ² νκ³ λ€μλλ° κ·Έλ₯ λ¬Έμ λ₯Ό μν΄μ λ§λ μ¬κ·μλ€μ.. |
μ§μ§ λ€μ λ΄λ μ΄ν΄ μλλκ² λ μ λμ λλ€.. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
리ν΄ν΄μ€ λ DPλ‘λ§ λ°κΏμ£Όλ©΄ λλκ΅°μ.! λ¬Έμ μ΄ν΄νλλ° μκ·Ό μ€λκ±Έλ Έμ΅λλ€..
import sys
input = sys.stdin.readline
def w(a, b, c):
if a <= 0 or b <= 0 or c <= 0:
return 1
elif a > 20 or b > 20 or c > 20:
return w(20, 20, 20)
if dp[a][b][c] :
return dp[a][b][c]
if a<b<c :
dp[a][b][c] = w(a,b,c-1) + w(a,b-1,c-1) - w(a,b-1,c)
else:
dp[a][b][c] = w(a-1,b,c) + w(a-1,b-1,c) + w(a-1,b,c-1) - w(a-1,b-1,c-1)
return dp[a][b][c]
dp = [[[0 for _ in range(21)] for _ in range (21)] for _ in range (21)]
while True:
a, b, c = map(int, input().split())
if a == -1 and b == -1 and c == -1:
break
print(f"w({a}, {b}, {c}) = {w(a,b,c)}")
π λ¬Έμ λ§ν¬
https://www.acmicpc.net/problem/9184 - μ λλ ν¨μ μ€ν
βοΈ μμλ μκ°
1μκ° - DP λ μ¬κ·λ₯Ό νμ§ μλλ€λ κ³ μ κ΄λ μ λ²λ €λΌ! λμ κ°μ λ§λ€λ©΄ λλ€!
β¨ μλ μ½λ
μ΄ μ¬κ· ν¨μλ₯Ό λμ κ³νλ² ννλ‘ λ°κΎΈλ λ¬Έμ μλλ°, Bottom Up λ°©μμΌλ‘ νλ €λ€κ° μκ°μ μ‘μλ¨Ήμλ€μ. λμ κ°μ μ¬κ·λ‘ λ°μλ λλκ±΄λ° κ³ μ κ΄λ μ μ‘νμμλ κ² κ°μ΅λλ€.
첫 λ²μ§Έμ λ λ²μ§Έ if λ¬Έμ ν΅ν΄ dpμ λ²μλ₯Ό μ ν μ μμ΅λλ€.
0λ³΄λ€ μμΌλ©΄ 1λ‘ λ¦¬ν΄ν΄μ£Όκ³ ,
20λ³΄λ€ ν¬λ©΄ w(20,20,20)μ νΈμΆνλ©΄ λκΈ° λλ¬Έμ
dp λ 3μ°¨μ λͺ¨λ λ€ 0~20 κΉμ§λ§ μ΄κΈ°ν μμΌλ©΄ λ©λλ€. (a,b,c μ κ°μ΄ 20μ λμ΄κ° μΌμ΄ μλ€λ λ§)
κ·Έλ¦¬κ³ dp κ°μ΄ μ‘΄μ¬νλ©΄ λ°λ‘ 리ν΄, μλ€λ©΄ ꡬνκ³ λ¦¬ν΄νλ©΄ λ©λλ€!
μ μ΄κ² μκ°μ΄ μ€λ κ±Έλ¦¬μ§ μλκ°λ₯Ό μκ°μ ν΄λ³΄μλλ°, λͺ¨λ κ²½μ°μ μλ₯Ό λ€ μ΄ν΄λ³΄μ§ μκ³ λμ κ°μ΄ μμΌλ©΄ λ°λ‘ λμ Έμ€ μ μκΈ° λλ¬Έμ
μκ°μ΄ ν! μ€μ΄λλ κ²μ΄λΌκ³ λ³Ό μ μμμ΅λλ€!
π μλ‘κ² μκ²λ λ΄μ©
νμ΄μ¬μ 3μ°¨μ 리μ€νΈ μ½κ² λ§λ€ μ μμΌλ λ무 μ΄λ ΅κ² μκ°νμ§ λ§μ!