BeautifulHexagonalTilings
SRM 355 · 2007-06-20 · by Petr
Problem Statement
Consider a hexagonal grid with 6 sides, with the side lengths given by the int[] s (in the clockwise order), as shown in the following picture:

Count the number of ways to color each cell with one of two colors, black or white, such that every non-border black cell has exactly a black neighbors, and every non-border white cell has exactly b white neighbors (a cell is called non-border if and only if it has exactly 6 neighbors in the grid).
Constraints
- s will contain exactly 6 elements.
- Each element of s will be between 2 and 6, inclusive.
- a and b will each be between 0 and 6, inclusive.
- s will define a valid hexagonal grid.
- The answer will always fit into an int.
{2,2,2,2,2,2}
6
6
Returns: 2
Either all white or all black.
{6,6,6,6,6,6}
6
6
Returns: 2
The field is bigger, but still all white or all black.
{2,2,2,2,2,2}
2
2
Returns: 30
{4,4,3,5,3,4}
4
1
Returns: 213
The grid from the picture.
{6,6,6,6,6,6}
2
2
Returns: 7926
Submissions are judged against all 112 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class BeautifulHexagonalTilings with a public method int howMany(vector<int> s, int a, int b) · 112 test cases · 2 s / 256 MB per case