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

[소병희] Java vs C++, 1,2,3 더하기 4, 도어맨, 배열 복원하기, 후위 표기식2 #44

Merged
merged 5 commits into from
Nov 13, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
solve: 1 2 3 더하기 4
bngsh committed Nov 13, 2022
commit 88f6e22a6432d0a713283957e5e43f8e834a5e3f
44 changes: 44 additions & 0 deletions src/main/kotlin/byeonghee/9week/1 2 3 더하기 4.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package byeonghee.`9week`

import java.io.*

class 소병희_123더하기4 {
companion object {
const val LAST_ONE = 0
const val LAST_TWO = 1
const val LAST_THREE = 2

val br = BufferedReader(InputStreamReader(System.`in`))
val dp = Array(10004) { intArrayOf(1, 0, 0) }
var tc = 0

fun solve() {
val t = br.readLine().toInt()

repeat(t) {
tc = br.readLine().toInt()
println(findCases(tc + 3, LAST_THREE))
}
}

fun findCases(n: Int, e: Int): Int {
if (n <= e) return 0
if (n == 1) return if (e == LAST_ONE) 1 else 0
if (n == 2) return if (e <= LAST_TWO) 1 else 0
if (n == 3) return if (e <= LAST_THREE) 1 else 0

if (dp[n][e] > 0) return dp[n][e]

var ans = 0
for(i in 0..e) {
ans += findCases(n - e - 1, i)
}
dp[n][e] = ans
return ans
}
}
}

fun main() {
소병희_123더하기4.solve()
}