

For the given if N = ‘3’, the possible number of arrangements is 5.
They are ‘000’,’101’, ‘001’,’100’ and ‘010’. Here 1 represents an Angry student and 0 represents a normal student.
The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains a single integer, 'N’ denoting the number of seats in the class.
For each test case, print an integer corresponding to the number of distinct possible arrangements % (10^9 +7).
Print the output of each test case in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N <= 5000.
Time limit: 1 sec
In this approach, we will declare a recursive function HELPER(‘CUR’, ’LAST’) that will return the number of arrangements with ‘CUR’ seats and the last student as ‘LAST’. The base case will be if CUR == 1, return 1.
If LAST is equal to 1, we can only add a 0, so return HELPER(‘CUR’-1,0).
If LAST is equal to 0,we can add both 1 and 0 ,so return ( HELPER(‘CUR’-1,1) + HELPER(‘CUR’-1,0) ) % (10^9 + 7).
Our final answer will be ( HELPER(‘N’,0) + HELPER(‘N’,1) ) %(10^9 + 7).
As in the approach-1, we have used a recursive function to find the answer. In this approach, we will use the same function but we will store the answer returned by the function in a DP array. So that if the answer is already computed, we can use that answer and reduce the time complexity efficiently.
In this approach, we will declare two arrays ‘LASTONE’ and ‘LASTZERO’. LASTONE[i] stores the number of arrangements possible that ends with ‘1’. Similarly, LASTZERO[i] will store the number of arrangements possible that ends with ‘0’. We will fill these as
We will return the final answer as (‘LASTONE’[‘N’] + ‘LASTZERO’[‘N’]) % (10^9 +7).