간단해 보이는 문제였는데 은근히 안 풀려서, 30분이 지나 다른 풀이를 참고했다. 풀이는 간단했는데 떠올려내기가 어려웠다.
DIVISOR = 1000000
if __name__ == "__main__":
code = list(map(int, input()))
N = len(code)
DP = [0] * (N+1)
if code[0] == 0:
print(0)
else:
code = [0] + code
DP[0] = DP[1] = 1
for i in range(2, N+1):
if code[i] > 0:
DP[i] += DP[i-1]
temp = code[i-1] * 10 + code[i]
if temp >= 10 and temp <= 26:
DP[i] += DP[i-2]
print(DP[N] % DIVISOR)
'알고리즘' 카테고리의 다른 글
[백준/파이썬] #21608 (0) | 2025.05.15 |
---|---|
[백준/파이썬] #16927 (0) | 2025.05.11 |
[백준/파이썬] #1062 (0) | 2025.05.05 |
[백준/파이썬] #14712 (0) | 2025.05.03 |
[백준/파이썬] #16987 (0) | 2025.05.01 |