DJ Boy is a new generation child he has never seen numeric keypad of mobile. So one day…
- User
DJ Boy is a new generation child he has never seen numeric keypad of mobile. So one day when Prem showed him his mobile, DJ boy started laughing on him. Prem being smart gave him a problem to solve with some condition. Your task is to help DJ boy to solve this problem:
Given a number N, DJ boy has to tell how many numbers of length N are possible.
Conditions:
1)He can only press digit that are adjacent i.e. to the left, right, up or bottom to current digit.
2)He may press the same key again i.e. numbers like 000 & 080 are possible for length 3.
3)He cannot press * and # keys.
Constraints:
1 ≤ t ≤ 100
0 ≤ N ≤ 10000
MOD: 10^9 + 9 Input:
First line contains T,the number of test cases. Next t lines contain a number N.
Output:
Print the required number modulo MOD.
SAMPLE INPUT 2 1 2
SAMPLE OUTPUT 10 36
Assistant
MOD = 10**9 + 9 # Precompute transitions and reverse transitions transitions = [ [0, 8], # 0 [1, 2, 4], # 1 [1, 2, 3, 5], # 2 [2, 3, 6], # 3 [1, 4, 5, 7], # 4 [2, 4, 5, 6, 8], # 5 [3, 5, 6, 9], # 6 [4, 7, 8], # 7 [0, 5, 7, 8, 9], # 8 [6, 8, 9] # 9 ] reverse_transitions = [[] for _ in range(10)] for prev_d in range(10): for next_d in transitions[prev_d]: reverse_transitions[next_d].append(prev_d) T = int(input()) for _ in range(T): n = int(input()) if n == 0: print(0) continue if n == 1: print(10) continue dp_prev = [1] * 10 for _ in range(2, n + 1): dp_new = [0] * 10 for d in range(10): for p in reverse_transitions[d]: dp_new[d] = (dp_new[d] + dp_prev[p]) % MOD dp_prev = dp_new print(sum(dp_prev) % MOD)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.