TopcoderArchiveVisit Topcoder
SRM26 Jan 2020
SRM 777

BlackAndWhiteBallsEasy

Problem statement, definition, constraints, and public examples.

Problem Statement

Some black and some white balls are placed in a row. You are given a int[] balls that describes the row using run-length encoding. That is, the row of balls looks as follows:

  • At the beginning there are balls[0] white balls.
  • Then there are balls[1] black balls.
  • After those there are balls[2] white balls again.
  • ... and so on, alternating between white and black.

You have to split the entire row into segments. Each segment must be labeled either "white" or "black". A segment labeled "white" must contain exactly white white balls (and arbitrarily many black ones). A segment labeled "black" must contain exactly black black balls (and arbitrarily many white ones).

Find the number of ways in which we can split the row into segments and assign colors to those segments. Return that value modulo 1,000,000,007.

Definition

Class:
BlackAndWhiteBallsEasy
Method:
getNumber
Parameters:
int[], int, int
Returns:
int
Method signature:
int getNumber(int[] balls, int white, int black)
(be sure your method is public)

Constraints

  • balls will contain between 1 and 50 elements, inclusive.
  • Each element of balls will be between 1 and 50, inclusive.
  • white and black will be between 1 and 50, inclusive.

Examples

  1. {2, 2}
    1
    2
    Returns: 4
    The row of balls looks as follows: WWBB. The four ways to split it are listed below. White segment W, white segment W, black segment BB. White segment W, white segment WBB. White segment W, black segment WBB. Black segment WWBB. Note that the second and third way are considered distinct: the division of the row into segments is the same but the labels are not.
  2. {2, 1, 3}
    1
    1
    Returns: 14
  3. {1, 1, 1, 1, 1}
    1
    1
    Returns: 28
  4. {2, 2, 2, 2, 2}
    1
    1
    Returns: 236
  5. {3, 6, 3, 10}
    2
    3
    Returns: 12
  6. {30, 15, 45, 20, 8, 13, 7, 3, 25, 10}
    3
    2
    Returns: 180210099
Back to all problems