Statistics

Problem Statement for "NarrowPassage2Easy"

Problem Statement

There is a narrow passage. Inside the passage there are some wolves. You are given a int[] size that contains the sizes of those wolves, from left to right.


The passage is so narrow that some pairs of wolves cannot pass by each other. More precisely, two adjacent wolves may swap places if and only if the sum of their sizes is maxSizeSum or less. Assuming that no wolves leave the passage, what is the number of different permutations of wolves in the passage? Note that two wolves are considered different even if they have the same size.


Compute and return the number of permutations of wolves that can be obtained from their initial order by swapping a pair of wolves zero or more times.

Definition

Class:
NarrowPassage2Easy
Method:
count
Parameters:
int[], int
Returns:
int
Method signature:
int count(int[] size, int maxSizeSum)
(be sure your method is public)

Constraints

  • size will contain between 1 and 6 elements, inclusive.
  • Each element in size will be between 1 and 1,000, inclusive.
  • maxSizeSum will be between 1 and 1,000, inclusive.

Examples

  1. {1, 2, 3}

    3

    Returns: 2

    From {1, 2, 3}, you can swap 1 and 2 to get {2, 1, 3}. But you can't get other permutations.

  2. {1, 2, 3}

    1000

    Returns: 6

    Here you can swap any two adjacent wolves. Thus, all 3! = 6 permutations are possible.

  3. {1, 2, 3}

    4

    Returns: 3

    You can get {1, 2, 3}, {2, 1, 3} and {2, 3, 1}.

  4. {1,1,1,1,1,1}

    2

    Returns: 720

    All of these wolves are different, even though their sizes are the same. Thus, there are 6! different permutations possible.

  5. {2,4,6,1,3,5}

    8

    Returns: 60

  6. {1000}

    1000

    Returns: 1

  7. {212,263,494}

    90

    Returns: 1

  8. {807}

    500

    Returns: 1

  9. {83}

    5

    Returns: 1

  10. {206}

    35

    Returns: 1

  11. {228,51}

    565

    Returns: 2

  12. {189,266}

    186

    Returns: 1

  13. {234,241,195,15}

    557

    Returns: 24

  14. {11,13,1,28,24}

    1

    Returns: 1

  15. {479,756,370,386,312}

    903

    Returns: 6

  16. {49,4}

    22

    Returns: 1

  17. {58,75,177,85,125,63}

    239

    Returns: 36

  18. {417,112,334,236,445}

    1000

    Returns: 120

  19. {75,53,43,209,93}

    459

    Returns: 120

  20. {93,104,126,79,4,144}

    221

    Returns: 72

  21. {56,258,84,543}

    114

    Returns: 1

  22. {696,246,21,617}

    276

    Returns: 2

  23. {3,3,4}

    11

    Returns: 6

  24. {20,90,138,21,109,121}

    165

    Returns: 30

  25. {63,142,577,170}

    36

    Returns: 1

  26. {187,221,184,50,141}

    158

    Returns: 1

  27. {79,110,26,206}

    367

    Returns: 24

  28. {185,213,470,79,410,230}

    341

    Returns: 1

  29. {67,127,163,267,576}

    949

    Returns: 120

  30. {739,197,952,292,521}

    107

    Returns: 1

  31. {706,98,748,22,535}

    135

    Returns: 1

  32. {134,130,717,519}

    720

    Returns: 2

  33. {25,16,22,21}

    29

    Returns: 1

  34. {337,268}

    192

    Returns: 1

  35. {228}

    572

    Returns: 1

  36. {543,548,567}

    414

    Returns: 1

  37. {12,4,37,29}

    114

    Returns: 24

  38. {7,272,296,87,152}

    64

    Returns: 1

  39. {7,3}

    9

    Returns: 1

  40. {461}

    903

    Returns: 1

  41. {226,349}

    919

    Returns: 2

  42. {95,97}

    156

    Returns: 1

  43. {373,173,91,338}

    754

    Returns: 24

  44. {441,410,236,177,348,346}

    24

    Returns: 1

  45. {127,95,246,120,165}

    48

    Returns: 1

  46. {61,58,17,65,7}

    49

    Returns: 1

  47. {204,481}

    161

    Returns: 1

  48. {17,75,85,80,14}

    123

    Returns: 20

  49. {42,128}

    18

    Returns: 1

  50. {651,134,452,329,515,616}

    780

    Returns: 5

  51. {245,138,159}

    481

    Returns: 6

  52. {145}

    876

    Returns: 1

  53. {360,408,294}

    24

    Returns: 1

  54. {709,776,736,307}

    693

    Returns: 1

  55. {569,554}

    514

    Returns: 1

  56. {204,188,263,209}

    35

    Returns: 1

  57. {502, 499, 498, 503, 102, 899 }

    1000

    Returns: 15

  58. {2, 4, 6, 1, 3, 5 }

    8

    Returns: 60

  59. {2, 1, 3, 3, 1, 2 }

    5

    Returns: 360

  60. {1, 1, 1, 1, 1, 1 }

    5

    Returns: 720

  61. {2, 1, 3, 3, 1, 3 }

    1000

    Returns: 720

  62. {1, 1, 1, 1, 1, 1 }

    1

    Returns: 1

  63. {1, 1, 2, 1, 1 }

    2

    Returns: 4

  64. {1, 1 }

    1

    Returns: 1

  65. {4 }

    2

    Returns: 1

  66. {1, 2, 3 }

    4

    Returns: 3

  67. {2, 1, 3 }

    4

    Returns: 3

  68. {1, 2, 3, 4, 5, 6 }

    6

    Returns: 15


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: