TopcoderArchiveVisit Topcoder
SRM20 Jun 2007
SRM 355

BeautifulHexagonalTilings

Problem statement, definition, constraints, and public examples.

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).

Definition

Class:
BeautifulHexagonalTilings
Method:
howMany
Parameters:
int[], int, int
Returns:
int
Method signature:
int howMany(int[] s, int a, int b)
(be sure your method is public)

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.

Examples

  1. {2,2,2,2,2,2}
    6
    6
    Returns: 2
    Either all white or all black.
  2. {6,6,6,6,6,6}
    6
    6
    Returns: 2
    The field is bigger, but still all white or all black.
  3. {2,2,2,2,2,2}
    2
    2
    Returns: 30
  4. {4,4,3,5,3,4}
    4
    1
    Returns: 213
    The grid from the picture.
Back to all problems