Colorful floors

3.8

22 votes
Dynamic Programming, Algorithms, 4D dynamic programming
Problem

The floor of your house consists of five rows of square tiles and each row is N tiles long.

You must paint the whole floor by using at most four colors such that the total number of ith (1i4) colored tiles in any two consecutive columns of the floor should not exceed K. Determine the number of ways in which you can paint the floor. 
Since the answer can be very large, compute it modulo 109+7.

Note: The floor should be completely painted. If there is no way to paint the floor completely, then print 0.

Input format

  • First line: Two space-separated integers N and K

Output format

Print a single integer that denotes the number of ways to paint the floor completely.

Constraints

1N10001K10

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

-

Editor Image

?