λ¬Έμ
λ°±μ€ μ¨λΌμΈ μ μ§ - 2688λ²
νμ΄ κ³Όμ
μ€μ΄λ€μ§ μλ n
μ리 μλ₯Ό ꡬνλ λ¬Έμ μ
λλ€.dp(num, digit) = num λ³΄λ€ ν¬κ±°λ κ°μ μλ‘ μμνλ digit μ리 μμ κ°μ
λΌκ³ μ μνλ€λ©΄
λ€μκ³Ό κ°μ μ νμμ λμΆν μ μμ΅λλ€.
dp(num, digit) = dp(num, digit - 1) + dp(num + 1, digit - 1) ...
μ΄λ `num` μ `0 <= num <= 9` μ΄μ΄μΌ νλ©° `n μ리μ` μ μ€μ΄λ€μ§ μλ μλ `dp(0~9, n)` μ λλ€.
μ½λ
T = int(input())
testcases = [int(input()) for _ in range(T)]
def solution():
memo = [[-1] * 65 for _ in range(10)]
for digit in range(1, 65):
for num in range(10):
memo[num][digit] = 0
if digit > 1:
for to in range(num, 10):
memo[num][digit] += memo[to][digit - 1]
else:
memo[num][digit] = 1
for n in testcases:
answer = 0
for num in range(10):
answer += memo[num][n]
print(answer)
solution()
λ°μν
'π algorithm > boj' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
BOJ 3109 - λΉ΅μ§ (0) | 2021.03.14 |
---|---|
BOJ 14620 - κ½κΈΈ (0) | 2021.03.14 |
BOJ 16472 - κ³ λ₯μ΄ (0) | 2021.03.14 |
BOJ 17086 - μκΈ° μμ΄2 (0) | 2021.03.08 |
BOJ 13335 - νΈλ (0) | 2021.03.08 |
π¬ λκΈ