-
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
13-alstjr7437 #43
13-alstjr7437 #43
Conversation
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 μΈμ§ λͺ¨λ₯΄κ³ νμ°Έ κ³ λ―Όνλ€κ° λΆλ₯ λ³΄κ³ νμλ€μ.. νΌ λ°©λ²μ λκ°μμ!
κ·Όλ° μ΄κ² μ«μκ° λ무 컀μ Long μΌλ‘ λ°κΏλ μλκΈΈλ κ° μ
λ°μ΄νΈ ν λλ λλ¨Έμ§λ₯Ό λ£λλ‘ν΄μ ν΄κ²°νμ΅λλΉ.
fun main() {
val br = BufferedReader(InputStreamReader(System.`in`))
val n = br.readLine().toInt()
val dp: Array<Array<Long>> = Array(n) { Array(10) { 1L } }
dp[0][0] = 0
for (i in 1 until n) {
for (j in 0..9) {
dp[i][j] = when (j) {
0 -> dp[i - 1][1]
9 -> dp[i - 1][8]
else -> dp[i - 1][j + 1] + dp[i - 1][j - 1] % 1_000_000_000
}
}
}
println(dp[n - 1].sumOf { it } % 1_000_000_000)
}
elif j == 9: | ||
dp[i][j] = dp[i-1][j-1] | ||
else : | ||
dp[i][j] = dp[i-1][j-1] + dp[i-1][j+1] |
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.
μ¬κΈ°μ μ΄ μ νμμ μ λμ€λμ§ μ΄ν΄κ° λμ§ μμμ ..γ γ
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.
jκ° 0μΌλλ μ€λ₯Έμͺ½ μμ μλκ±Έ κ°μ Έμ€κ³
jκ° 9μΌλλ μΌμͺ½ μμ μλκ±Έ κ°μ Έμ€κ³
κ·Έ λλ€ μλλλ μΌμͺ½ μ, μ€λ₯Έμͺ½ μλ₯Ό κ°μ Έμμ λνλ©΄ λμ κ·Έλ μ΅λλ€!
π λ¬Έμ λ§ν¬
μ¬μ΄ κ³λ¨ μ
λ³ν κ³λ¨ μβοΈ μμλ μκ°
40λΆ
β¨ μλ μ½λ
μ°μ μ μΌλ‘ κ³λ¨ μλ₯Ό κ·Έλ₯ νλμ© λ€ μ μ΄λ³΄λ©΄μ μ΄λ€ μ νμμ μΈμΈ μ μμκΉ μκ°μ νμ΅λλ€!
μ²μμλ 1λ²μ΄ μ΄λ»κ² ν΄λ μλμμ΄μ μΈν°λ·μ μ¬μ© μ°Έκ³ ν΄λ³΄λ
0λ²μ 1λ²μ μλκ±Έ κ°μ Έμμ μ¬μ©νλ©΄ λμμ΅λλ€!!
μ μ¬μ§κ³Ό κ°μ΄ μ΄λ€ μ νμμΌλ‘ λ€μ΄κ°μ§ μΈμ κ³
i -> κ³λ¨ μ j -> μμνλ μ«μ
dp[i][j]
dp[3][3]μ μλ‘ λ€λ©΄
3μ κ³λ¨μμ 3μΌλ‘ μμνλκ² λͺκ° μλμ§ λ€μ΄κ°λλ€.
2λ²μΌλ‘ λ€κ³ μμ 2μΈ΅μ 2μ μ(2) + 2μΈ΅μ 4μ μ(2) = 4λ‘ λ€μ΄κ°κ² λ©λλ€.
κ·Έλ κ² μμ κ°μ΄ κ³μ°μ νμ¬μ nμ 1λ² μΈλ±μ€λΆν° 9λ² μΈλ±μ€κΉμ§ λν΄μ λλ 쀬μ΅λλ€.
μ 체 μ½λ
π μλ‘κ² μκ²λ λ΄μ©
DPμ μ νμ μΈμ°λ λΆλΆμ΄ 0λ² μΈλ±μ€λ μ°Έ μ€μνλ€κ³ κΉ¨λ«μ΅λλ€...
κ·Έλ₯ μμ΄ 1λ²λΆν° μΈμ λ€κ° μκ°μ 20λΆ μ λ λ²λ¦° κ² κ°λ€μ..
μκ°μ΄ λλ€λ©΄ λ³ν κ³λ¨ μλ νμ΄λ³΄κ³ PRμ μΆκ°νκ² μ΅λλ€..
λ°λ‘ 20λΆμ μκ°ν΄λ΄λ μμ΄λμ΄κ° μλ μ¬λΌμ λ§νλ€μ...