Fill Grid

3.5

4 votes
Implementation, C++, Permutation Cycles, Brute Force, Combinatorics, Math
Problem

Given an empty grid with 4 rows and n columns, count the number of ways to fill the grid with 0's and 1's, such that for all the 4 x 4 subgrids, they contain an equal amount of 1's in them. Since the number of ways could be quite large, you should find it modulo 109+7.

Note: It is possible to have zero 1's in the subgrids.

A subgrid is a grid made up of a subset of the larger grid. 

 Input format

  • The first line contains an integer, t - denoting the number of test cases. 
  • The next t lines of the input each contain an integer, ni - denoting the number of columns the grid has in the ith test case.

Output format

Your program should output t lines, each line denoting the total number of ways to fill a grid of 4 rows and ni columns modulo 109+7 for the ith test case.

Constraints

1t10004ni1018

 

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

In the sample input, we have one test case with n=5

Below are some 4 x 5 grids that satisfy the condition, with the 4 x 4 subgrids highlighted.

 

Editor Image

?