baekjoon 20251209
This commit is contained in:
parent
4aa7d1cdd3
commit
9a663e093f
26
code_study/Baekjoon/python/1562.py
Normal file
26
code_study/Baekjoon/python/1562.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
N = int(input())
|
||||||
|
MOD = 10**9
|
||||||
|
|
||||||
|
dp = [[[0]*1024 for _ in range(10)] for _ in range(N+1)]
|
||||||
|
|
||||||
|
for i in range(1,10) :
|
||||||
|
dp[1][i][1<<i] = 1
|
||||||
|
|
||||||
|
for length in range(1,N) :
|
||||||
|
for last_num in range(10) :
|
||||||
|
for bit_state in range(1024) :
|
||||||
|
if dp[length][last_num][bit_state] == 0 : continue
|
||||||
|
|
||||||
|
next_num = last_num - 1
|
||||||
|
if 0 <= next_num <= 9 :
|
||||||
|
next_bit_state = bit_state | (1<<next_num)
|
||||||
|
dp[length+1][next_num][next_bit_state] += dp[length][last_num][bit_state]
|
||||||
|
dp[length+1][next_num][next_bit_state] %= MOD
|
||||||
|
|
||||||
|
next_num = last_num + 1
|
||||||
|
if 0 <= next_num <= 9 :
|
||||||
|
next_bit_state = bit_state | (1<<next_num)
|
||||||
|
dp[length+1][next_num][next_bit_state] += dp[length][last_num][bit_state]
|
||||||
|
dp[length+1][next_num][next_bit_state] %= MOD
|
||||||
|
|
||||||
|
print(sum(dp[N][i][1023] for i in range(10))%MOD)
|
||||||
Loading…
x
Reference in New Issue
Block a user