Ball Painting
Time limit2sMemory limit512 MB
Count paint orders on a 2 by N grid where each new ball must touch an already painted ball, modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
There are white balls on a table, arranged in two rows to form a rectangle. Jon has a bucket full of black paint and wants to paint every ball black, one ball at a time, following these rules:
- The first ball he paints can be any of the balls.
- Every ball painted afterward must be adjacent to some ball that is already black. Two balls are adjacent when they sit next to each other horizontally, vertically, or diagonally.
Count the number of different orders in which Jon can paint all balls while obeying the rules.
Input
The input consists of several test cases. Each test case is a single line containing an integer (). The input ends with a line containing .
Output
For each test case, print on its own line the number of orders in which Jon can paint all balls according to the rules. This number can be very large, so print it modulo 1,000,000,007.