TopcoderArchiveVisit Topcoder
SRM14 Jun 2002
SRM 98

Catan

Problem statement, definition, constraints, and public examples.

Problem Statement

In the game "Settlers of Catan", a number of six-sided dice are rolled and their sum is calculated (each die is a cube with the numbers 1 through 6 on its faces). A useful statistic to know when playing the game is the number of possible ways to roll a given sum, with a given number of dice. For example, you can get the sum of 2 by rolling 2 dice in only one way: rolling 1 and 1. You can get the sum of 3 by rolling 2 dice in two ways: 1 on the first die and 2 on the second or vice versa.

Your task is write a class Catan, with a method sumCount, which takes an int, numDice, and an int, sum, and returns the number of ways to roll sum using numDice. All of the dice are considered different, so to roll 1 on the first die and 3 on the second die is a different way to roll 4 than rolling 3 on the first die and 1 on the second die.

Definition

Class:
Catan
Method:
sumCount
Parameters:
int, int
Returns:
long
Method signature:
long sumCount(int numDice, int sum)
(be sure your method is public)

Notes

  • The long data type is a 64-bit signed integer. Note for C++ coders: The long data type is specific to the gcc compiler.

Constraints

  • numDice is between 1 and 20 inclusive
  • sum is between 0 and 200 inclusive

Examples

  1. 2
    2
    Returns: 1
  2. 2
    2
    Returns: 1
  3. 2
    2
    Returns: 1
  4. 20
    19
    Returns: 0
  5. 5
    29
    Returns: 5
  6. 20
    70
    Returns: 189456975899496
Back to all problems