RowOfColors
TCO11 Round 3 · 2011-05-07 · by vexorian
Problem Statement
- The top-most row must contain at least one cell of each of the k colors.
- Every pair of cells of the same color must be connected. Two cells are connected if there is a path between them that consists of cells that share a common edge and are of the same color.
Constraints
- w, h and k will each be between 1 and 300, inclusive.
4 1 2 Returns: 6
There is only one row in the grid. The 6 different ways to color the grid with 2 different colors such that the cells of each color are connected are: "AAAB", "AABB", "ABBB", "BBBA", "BBAA" and "BAAA".
4 3 2 Returns: 12
This time "ABAA", "AABA", "ABBA", "BABB", "BBAB" and "BAAB" are new valid ways to color the top-most row in the grid. The following are some of the grid colorings that allow those top rows: ABAA AABA ABBA BABB BBAB BAAB ABBA AAAA ABAA BABB BAAB BBBB AAAA AAAA AAAA BBBB BBBB BBBB
4 4 10 Returns: 0
It is impossible to use each of the 10 different colors on the 4 cells in the top row.
14 28 14 Returns: 178290591
100 20 25 Returns: 148201539
4 4 3 Returns: 36
AABC ABAC ABCA ABCC ABCB ABBC
Submissions are judged against all 114 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class RowOfColors with a public method int countWays(int w, int h, int k) · 114 test cases · 2 s / 256 MB per case