Problem 7: Abstract Painting

https://open.kattis.com/problems/abstractpainting

Color square by square, starting at the top-left square.

To color the top-left square, there are (32)=3\binom{3}{2} = 3ways to choose the two colors for the square. Then, there are (42)=6\binom{4}{2}=6 ways to arrange these colors. So, there are 36=183 \cdot 6 = 18ways to color the top-left square.

Next, move right and color the rest of the squares in the first row. For these squares, we'll have already colored the square to the left, which means one line is colored already. So, one color is already fixed, and there are then (21)=2\binom{2}{1}=2choices for the second color. Moreover, there are (32)=3\binom{3}{2}=3ways to arrange the remaining three lines of the square. So, there are 23=62 \cdot 3 = 6ways to color the squares of the first row. Similarly, there are 66ways to color the squares of the first column as well.

For the rest of the squares, we can keep coloring squares with two lines already colored, until we have colored the entire painting. For each square with two lines already colored, there are two cases:

  • Both lines are the same color: there are (21)=2\binom{2}{1}=2ways to choose the second color, and only 11way to color the remaining two lines (both must be the other color). So, there are 21=22 \cdot 1=2colorings.

  • The two lines are different colors: both colors of the square are defined by these two lines. There are (21)=2\binom{2}{1}=2ways to color the remaining two lines. So there are 21=22 \cdot 1=2colorings.

Therefore, for these squares, there are always 22colorings.

So, to count the total number of good paintings, start with 18 for the first square. Multiply by 6 for each other square in the first row or first column, and multiply by 2 for every other square. That gives us the expression:

Remember to take mod 1000000007 after each multiplication step to avoid integer overflow! Also, use long longs.

Last updated