TopCoder problem "DominoesFinding" used in TCCC06 Semi 2 (Division I Level Two)



Problem Statement

    

Dominoes is a fun game that requires 28 pieces, each representing a different pair of numbers between 0 and 6, inclusive. Since the pieces are reversible, (1,6) is the same piece as (6,1), and there is only one piece of the form (x,x) for each x.

The 28 pieces of dominoes are:

  (0,6) (0,5) (0,4) (0,3) (0,2) (0,1) (0,0)
  (1,6) (1,5) (1,4) (1,3) (1,2) (1,1)
  (2,6) (2,5) (2,4) (2,3) (2,2)
  (3,6) (3,5) (3,4) (3,3)
  (4,6) (4,5) (4,4)
  (5,6) (5,5)
  (6,6)

The problem with dominoes is that you need at least two people to play, so magazines have invented a game that you can play on your own. In a board with 7 columns and 8 rows there are numbers from 0 to 6, inclusive. The goal of the game is to divide the board into 28 2x1 rectangles in such a way that each part corresponds to one of the pieces and each piece is represented exactly once in the divided board.

When a magazine publishes an instance of the game (i.e., a board with the numbers), they want to ensure that it has a solution, and that the number of possible correct solutions is small so as to make the game more difficult.

Given the board as a String[] with each character representing a number between 0 and 6, return the number of correct solutions that board has.

 

Definition

    
Class:DominoesFinding
Method:getPossibilities
Parameters:String[]
Returns:int
Method signature:int getPossibilities(String[] board)
(be sure your method is public)
    
 

Constraints

-board will contain exactly 8 elements.
-Each element of board will contain exactly 7 characters.
-Each character of each element of board will be a domino digit ('0'-'6').
 

Examples

0)
    
{"0000000",
 "0123456",
 "1111112",
 "1234562",
 "2222333",
 "3456345",
 "3444556",
 "6456566"}
Returns: 60
1)
    
{"1111111","1111111","1111111","1111111","1111111","1111111","1111111","1111111"}
Returns: 0
No way!
2)
    
{"0054450",
 "6645056",
 "0151226",
 "6522303",
 "0246343",
 "6411432",
 "0324531",
 "6215131"}
Returns: 1
Only one way to solve this one.

+---+-+---+-+-+
|0 0|5|4 4|5|0|
+---+ +---+ | |
|6 6|4|5 0|5|6|
+---+-+-+-+-+-+
|0 1|5|1|2 2|6|
+---+ | +---+ |
|6 5|2|2|3|0|3|
+---+-+-+ | +-+
|0 2|4|6|3|4|3|
+---+ | +-+-+ |
|6 4|1|1|4 3|2|
+---+-+-+---+-+
|0 3|2 4|5 3|1|
+---+---+---+ +
|6 2|1 5|1 3|1|
+---+---+---+-+

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=6161

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10133&pm=6161

Writer:

soul-net

Testers:

PabloGilberto , brett1479 , Olexiy , Jan_Kuipers

Problem categories:

Brute Force, Recursion, Search