Statistics

Problem Statement for "Animals"

Problem Statement

A farmer has a number of animals on his farm. He has several different types of animals. Given the number of total heads that are present at the farm, the number of total legs, and the number of legs of each type of animal, return the number of different configurations the farmer could possibly have. A configuration is how many of each type of animal the farmer has. For two configurations to be different, the number of at least one type of animal needs to be different.

For example, if the farmer raises sheep, monkeys, butterflies, and cows, the four types of animals would have 4, 2, 6, and 4 legs respectively. If legs is 4 and heads is 1, the farmer has two possible configurations, 1 sheep, or 1 cow.

Create a class Animals that contains the method numWays, which takes three arguments:
heads: how many heads of animals are present on the farm
legs: how many legs of animals are present on the farm
types: a int[] whose elements tell how many legs each type of animal has.
The method should return an int, which should be how many possible different configurations of animals there could be.

Definition

Class:
Animals
Method:
numWays
Parameters:
int, int, int[]
Returns:
int
Method signature:
int numWays(int heads, int legs, int[] types)
(be sure your method is public)

Notes

  • All animals on the farm have exactly one head.
  • There are no animals on the farm with missing limbs.

Constraints

  • heads is between 1 and 200 inclusive
  • legs is between 1 and 2000 inclusive
  • types has between 1 and 5 elements inclusive
  • Each element of types is between 1 and 15 inclusive

Examples

  1. 1

    4

    {4,2,6,4}

    Returns: 2

    This is the example stated above.

  2. 100

    400

    {4,4}

    Returns: 101

    If the farmer has sheep and cows, there are 101 different possibilities. The configurations are: (0 cows, 100 sheep), (1 cow, 99 sheep), (2 cows, 98 sheep), ..., (99 cows, 1 sheep), (100 cows, 0 sheep).

  3. 100

    300

    {1,2,3,4,5}

    Returns: 29920

  4. 59

    230

    {2,15,11,1,8}

    Returns: 645

  5. 200

    200

    {1,1,1,1,1}

    Returns: 70058751

  6. 200

    2000

    {10,10,10,10,10}

    Returns: 70058751

  7. 200

    2000

    {11,12,13,14,15}

    Returns: 0

  8. 10

    15

    {1,2,3,4,5}

    Returns: 6

  9. 25

    13

    {1}

    Returns: 0

  10. 200

    205

    {1,1,1,1,1}

    Returns: 0

  11. 200

    599

    {3,3,3,3,3}

    Returns: 0

  12. 15

    200

    {8,14,12,1,6}

    Returns: 3

  13. 25

    250

    {8,9,10,11,12}

    Returns: 579

  14. 20

    98

    {1,3,5,7,11}

    Returns: 267

  15. 80

    108

    {1,15}

    Returns: 1

  16. 123

    456

    {7,8,9,10,11}

    Returns: 0

  17. 200

    2000

    { 10, 1, 1, 1, 1 }

    Returns: 1

  18. 200

    200

    { 1, 1, 1, 1, 1 }

    Returns: 70058751

  19. 200

    800

    { 4, 4, 4, 4, 4 }

    Returns: 70058751

  20. 200

    2000

    { 10, 10, 10, 10, 10 }

    Returns: 70058751

  21. 200

    2000

    { 1, 2, 3, 4, 5 }

    Returns: 0

  22. 200

    2000

    { 1, 3, 9, 14, 15 }

    Returns: 48178

  23. 200

    2000

    { 2, 3, 7, 11, 13 }

    Returns: 27254

  24. 200

    2000

    { 10, 1, 1, 1, 1 }

    Returns: 1

  25. 200

    200

    { 1, 1, 1, 1, 1 }

    Returns: 70058751

  26. 200

    800

    { 4, 4, 4, 4, 4 }

    Returns: 70058751

  27. 200

    2000

    { 10, 10, 10, 10, 10 }

    Returns: 70058751

  28. 200

    2000

    { 1, 2, 3, 4, 5 }

    Returns: 0

  29. 200

    2000

    { 1, 3, 9, 14, 15 }

    Returns: 48178

  30. 200

    2000

    { 2, 3, 7, 11, 13 }

    Returns: 27254


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: