Absent?

4

1 votes
Probablity, Dynamic Programming, Algorithms, Math, Basic Probability
Problem

John is attending a workshop for N days. He gets into trouble if he misses the workshop for two consecutive days.

Task

Determine the probability of him getting into trouble if he misses the workshop organized on the last day.

It can be shown that the probability can be represented as PQ where P and Q are coprime integers. Print the value of P*Q-1 modulo 109+7.

Note: There is an equal probability of John getting absent or present on any day.

Example

Assumption

  • N = 2

Approach

  • All possible combinations are (A,A) and (P,A) where P = Present , A = Absent.
  • Out of these, only (A, A) gets john into trouble.
  • The probability of this is 1/2. Thus the value of (1/2) modulo (109+7) is 500000004.

Therefore the answer is 500000004.

Function description

Complete the absent function provided in the editor. This function takes the following parameter and returns the probability of John getting into trouble:

  • N: Represents the number of days of the workshop

Input format

Note: This is the input format you must use to provide custom input (available above the Compile and Test button).

  • The first line contains denoting the number of test cases. T also specifies the number of times you have to run the absent function on a different set of inputs.
  • For each test case:
    • The first line contains N denoting the number of days of the workshop

Output format

For each test case in a new line, print the required probability.

Constraints

1T1051N105

Code snippets (also called starter code/boilerplate code) 

This question has code snippets for C, CPP, Java, and Python.

Sample Input
1
3
Sample Output
500000004
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The first line denotes the number of test cases, T = 1.

The first test case

Given

  • N = 3

Approach

  • The possible cases are (AAA), (APA), (PAA), (PPA).
  • Out of which 1st and 3rd cases get John in trouble.
  • The probability is 2/4 which is the same as (1/2). Thus the value of (1/2) modulo (109+7) is 500000004.

Therefore the answer is 500000004.

Editor Image

?