Connection Status:
Competition Arena > Catan
SRM 98 · 2002-06-14 · by axchma
Class Name: Catan
Return Type: long
Method Name: sumCount
Arg Types: (int, int)
Problem Statement

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.

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
0)
20
21
Returns: 20
1)
20
119
Returns: 20
2)
20
121
Returns: 0
3)
2
2
Returns: 1
4)
2
3
Returns: 2

Submissions are judged against all 45 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class Catan with a public method long long sumCount(int numDice, int sum) · 45 test cases · 2 s / 256 MB per case

Submitting as anonymous