A regular octagon with vertices X1, X2,..., X8 is provided. A frog starts jumping from…
- User
A regular octagon with vertices X1, X2,..., X8 is provided. A frog starts jumping from the vertex X1. It may jump to any of the two adjacent vertices in one jump except from X5. When it reaches X5, it stops and stays there. Let P(n) be the number of distinct paths of exactly n jumps ending at X5. Given the value of n, you need to print the value of P(n). Input The first line of the input contains the number of test cases T, at most 100. Each of the next T lines contain a single integer N, where 1 ≤ N ≤ 100.
Output For each value of N in the input, print on a new line the number of distinct paths of exactly n jumps ending at X5.
Example
Input: 3 1 2 4
Output: 0 0 2
Assistant
def main(): import sys input = sys.stdin.read().split() T = int(input[0]) cases = list(map(int, input[1:T+1])) adj = { 1: [2, 8], 2: [1, 3], 3: [2, 4], 4: [3], 6: [7], 7: [6, 8], 8: [7, 1], } for n in cases: if n == 1: print(0) continue steps = n - 1 dp = [0] * 9 dp[1] = 1 for _ in range(steps): new_dp = [0] * 9 for pos in range(1, 9): if pos == 5: continue count = dp[pos] if count == 0: continue for neighbor in adj[pos]: new_dp[neighbor] += count dp = new_dp print(dp[4] + dp[6]) if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.