Akash is feeling lonely.So he decided to visit his friend's house. His friend's house is…
- User
Akash is feeling lonely.So he decided to visit his friend's house. His friend's house is located at the distance of K metres from his house.Now,he can take a step of one metre ,two metres or three metres at a time.Can you tell me number of ways of reaching Akash's friend house. As the answer can be large Print answer mod 1000000007 Input
First line contains an integer t denoting number of test cases Next t lines contains an integer k
Output
Print t lines containing number of ways to to reach friend's house modulo 1000000007
SAMPLE INPUT 2 2 3
SAMPLE OUTPUT 2 4
Assistant
pythonMOD = 10**9 + 7 t = int(input()) test_cases = [] max_k = 0 for _ in range(t): k = int(input()) test_cases.append(k) if k > max_k: max_k = k # Handle the case where all test cases are 0 if max_k >= 0: dp = [0] * (max_k + 1) dp[0] = 1 if max_k >= 1: dp[1] = 1 if max_k >= 2: dp[2] = 2 for i in range(3, max_k + 1): dp[i] = (dp[i-1] + dp[i-2] + dp[i-3]) % MOD else: dp = [] for k in test_cases: print(dp[k] % MOD)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.