Statistics

Problem Statement for "LittleElephantAndPermutationDiv2"

Problem Statement

This problem statement contains superscripts and/or subscripts. These may not display properly outside the applet.

Little Elephant from the Zoo of Lviv likes permutations. A permutation of size N is a sequence (a1, ..., aN) that contains each of the numbers from 1 to N exactly once. For example, (3,1,4,5,2) is a permutation of size 5.

Given two permutations A = (a1, ..., aN) and B = (b1, ..., bN), the value magic(A,B) is defined as follows: magic(A,B) = max(a1,b1) + max(a2,b2) + ... + max(aN,bN).

You are given the int N. You are also given another int K. Return the number of pairs (A,B) such that both A and B are permutations of size N, and magic(A,B) is greater than or equal to K. (Note that A and B are not required to be distinct.)

Definition

Class:
LittleElephantAndPermutationDiv2
Method:
getNumber
Parameters:
int, int
Returns:
long
Method signature:
long getNumber(int N, int K)
(be sure your method is public)

Constraints

  • N will be between 1 and 10, inclusive.
  • K will be between 1 and 100, inclusive.

Examples

  1. 1

    1

    Returns: 1

    For N=1 the only pair of permutations is ( (1), (1) ). The magic of this pair of permutations is 1, so we count it.

  2. 2

    1

    Returns: 4

    Now there are four possible pairs of permutations. They are shown below, along with their magic value. magic( (1,2), (1,2) ) = 1+2 = 3 magic( (1,2), (2,1) ) = 2+2 = 4 magic( (2,1), (1,2) ) = 2+2 = 4 magic( (2,1), (2,1) ) = 2+1 = 3 In all four cases the magic value is greater than or equal to K.

  3. 3

    8

    Returns: 18

    When A = (1,2,3), there are 3 possibilities for B: (2,3,1), (3,1,2) and (3,2,1). For each of the other 5 values of A, it can be shown that there are 3 possibilities for B as well. Therefore the answer is 3*6 = 18.

  4. 10

    47

    Returns: 13168189440000

  5. 7

    1

    Returns: 25401600

  6. 7

    7

    Returns: 25401600

  7. 7

    47

    Returns: 0

  8. 10

    100

    Returns: 0

  9. 9

    74

    Returns: 0

  10. 9

    65

    Returns: 1881169920

  11. 10

    80

    Returns: 52254720000

  12. 10

    70

    Returns: 9397924300800

  13. 10

    65

    Returns: 12799692057600

  14. 10

    57

    Returns: 13168153152000

  15. 10

    40

    Returns: 13168189440000

  16. 10

    47

    Returns: 13168189440000

  17. 10

    1

    Returns: 13168189440000

  18. 10

    12

    Returns: 13168189440000

  19. 9

    50

    Returns: 131413726080

  20. 9

    1

    Returns: 131681894400

  21. 8

    1

    Returns: 1625702400

  22. 7

    1

    Returns: 25401600

  23. 6

    1

    Returns: 518400

  24. 5

    1

    Returns: 14400

  25. 4

    1

    Returns: 576

  26. 3

    1

    Returns: 36

  27. 7

    32

    Returns: 24857280

  28. 6

    17

    Returns: 518400

  29. 5

    7

    Returns: 14400

  30. 6

    15

    Returns: 518400

  31. 5

    10

    Returns: 14400

  32. 1

    100

    Returns: 0

  33. 8

    100

    Returns: 0

  34. 10

    66

    Returns: 12496977561600

  35. 10

    89

    Returns: 0

  36. 10

    30

    Returns: 13168189440000

  37. 10

    62

    Returns: 13133723097600

  38. 10

    55

    Returns: 13168189440000

  39. 10

    99

    Returns: 0

  40. 10

    88

    Returns: 0

  41. 10

    60

    Returns: 13164284851200

  42. 10

    56

    Returns: 13168185811200

  43. 10

    11

    Returns: 13168189440000

  44. 3

    20

    Returns: 0

  45. 5

    16

    Returns: 14280

  46. 3

    100

    Returns: 0

  47. 4

    14

    Returns: 96

  48. 2

    4

    Returns: 2

  49. 1

    2

    Returns: 0

  50. 4

    100

    Returns: 0

  51. 10

    67

    Returns: 12033071769600

  52. 4

    12

    Returns: 480

  53. 8

    40

    Returns: 1619412480

  54. 5

    21

    Returns: 2400

  55. 2

    100

    Returns: 0

  56. 5

    17

    Returns: 13800

  57. 10

    73

    Returns: 5323972147200


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: