Statistics

Problem Statement for "LineOfDice"

Problem Statement

A game die is a cube with the numbers 1 to 6 written on its sides: 1 - on the top, 2 - on the left, 3 - on the front, 4 - on the back, 5 - on the right, 6 - on the bottom. You have thrown n dice, and the numbers on their tops (after they've been thrown) are given in the int[] dice. The i-th element (1-based) of dice is equal to the number of dice that were dropped with the number i on top.

You want to construct a single straight line using one or more of these thrown dice. Each pair of adjacent dice must have the same number on the sides where they touch each other. You may rotate dice as long as the numbers on their tops don't change. Each die may be used at most once.

Determine the number of different ways you can construct a single straight line using the thrown dice. Return this number modulo 10007. Two lines are different if:

1. They have different lengths.
or
2. Orient both lines horizontally and compare them from left to right. If two dice at the same position in each line have different orientations, the lines are different. Note that the lines 1-3-6 and 6-3-1 are considered different under this rule.

Definition

Class:
LineOfDice
Method:
howMany
Parameters:
int[]
Returns:
int
Method signature:
int howMany(int[] dice)
(be sure your method is public)

Constraints

  • dice will contain exactly 6 elements.
  • Each element of dice will be between 0 and 1000, inclusive.

Examples

  1. {1,0,0,0,0,1}

    Returns: 16

    We have one die with a 1 on top, and one die with a 6 on top. There are 4 different ways to construct a line containing only the die with 1 on top (each of the 4 possible rotations of a single die). Similarly, there are 4 different lines that contain only the die with 6 on top. We can also put both dice into a line. There are 4 possible rotations where the two dice can touch each other (on sides 2, 3, 4 and 5). Then, for each of these, we can reverse the left-right order to create different lines, for a total of 8 different lines containing both dice. Thus there are 4 + 4 + 8 = 16 different lines.

  2. {1,1,0,0,0,0}

    Returns: 12

    We have one die with a 1 on top, and one die with a 2 on top. There are 4 different lines that contain only the die with 1 on top, and 4 different lines that contain only the die with 2 on top. There are only 2 possible rotations where the dice can touch each other (on sides 3 and 4), and for each of these, we can reverse the left-right order to get different lines.

  3. {0,0,2,0,0,0}

    Returns: 8

    We have 2 dice, both with 3 on top. Unlike the previous examples, where the dice had different numbers on top, there are only 4 different ways to construct a line containing only one die. There are 4 possible rotations where the dice can touch each other to form a line (on sides 1, 2, 5 and 6). Reversing left-right order doesn't produce different lines in this case because each line is horizontally symmetrical.

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

    Returns: 384

  5. {0,2,3,1,7,9}

    Returns: 8258

  6. {2, 2, 2, 2, 1, 2}

    Returns: 2074

  7. {1,1,0,0,1,1}

    Returns: 144

  8. {1,1,1,0,0,0}

    Returns: 24

  9. {0,2,3,1,7,9}

    Returns: 8258

  10. {1,1,1,1,1,1}

    Returns: 384

  11. {110,111,113,212,115,311}

    Returns: 8951

  12. {0,0,0,0,0,0}

    Returns: 0

  13. {992,0,0,0,0,0}

    Returns: 3968

  14. {0,991,0,0,0,0}

    Returns: 3964

  15. {998,1000,0,0,0,0}

    Returns: 5296

  16. {0,0,997,0,0,0}

    Returns: 3988

  17. {992,0,997,0,0,0}

    Returns: 8208

  18. {0,996,991,0,0,0}

    Returns: 4677

  19. {1000,991,993,0,0,0}

    Returns: 738

  20. {0,0,0,998,0,0}

    Returns: 3992

  21. {991,0,0,994,0,0}

    Returns: 2918

  22. {0,997,0,994,0,0}

    Returns: 296

  23. {990,997,0,998,0,0}

    Returns: 6792

  24. {0,0,992,998,0,0}

    Returns: 8553

  25. {997,0,991,996,0,0}

    Returns: 5132

  26. {0,997,991,995,0,0}

    Returns: 9936

  27. {996,990,990,991,0,0}

    Returns: 2961

  28. {0,0,0,0,994,0}

    Returns: 3976

  29. {996,0,0,0,1000,0}

    Returns: 3625

  30. {0,997,0,0,991,0}

    Returns: 8186

  31. {994,992,0,0,992,0}

    Returns: 5389

  32. {0,0,992,0,999,0}

    Returns: 5309

  33. {990,0,992,0,1000,0}

    Returns: 6564

  34. {0,993,995,0,997,0}

    Returns: 3198

  35. {994,995,996,0,998,0}

    Returns: 9427

  36. {0,0,0,995,1000,0}

    Returns: 2708

  37. {992,0,0,993,993,0}

    Returns: 2993

  38. {0,1000,0,995,995,0}

    Returns: 3411

  39. {993,993,0,997,993,0}

    Returns: 6385

  40. {0,0,998,1000,998,0}

    Returns: 8077

  41. {992,0,997,998,998,0}

    Returns: 5332

  42. {0,994,990,1000,999,0}

    Returns: 8168

  43. {993,993,993,1000,995,0}

    Returns: 421

  44. {288,331,690,868,150,398}

    Returns: 6967

  45. {766,226,155,428,727,190}

    Returns: 460

  46. {162,287,455,502,829,253}

    Returns: 4038

  47. {18,415,200,52,161,496}

    Returns: 7455

  48. {61,755,793,951,171,198}

    Returns: 1613

  49. {924,265,983,831,527,502}

    Returns: 5518

  50. {507,631,486,563,805,31}

    Returns: 1763

  51. {33,915,252,3,93,546}

    Returns: 9626

  52. {752,632,787,701,280,32}

    Returns: 5156

  53. {101,322,740,780,313,863}

    Returns: 2277

  54. {1000,998,999,995,998,995}

    Returns: 336

  55. {997,998,996,995,1000,999}

    Returns: 9498

  56. {1000,1000,1000,1000,1000,1000}

    Returns: 6271

  57. {0,1,0,3,1,0}

    Returns: 140

  58. {3,2,2,968,2,862}

    Returns: 436

  59. {0,2,2,0,2,937}

    Returns: 249

  60. {0,3,2,3,0,789}

    Returns: 3308

  61. {708,0,822,712,1,0}

    Returns: 547

  62. {2,3,2,2,2,3}

    Returns: 240

  63. {2,2,1,2,0,939}

    Returns: 2312

  64. {2,1,8,10,7,2}

    Returns: 5063

  65. {7,6,1,10,1,3}

    Returns: 2351

  66. {8,1,4,7,4,0}

    Returns: 9753

  67. {7,8,2,8,7,1}

    Returns: 3585

  68. {6,7,1,5,6,0}

    Returns: 7125

  69. {0,1,4,6,10,7}

    Returns: 5448

  70. {1,4,2,2,2,9}

    Returns: 4053

  71. {0,2,10,3,5,7}

    Returns: 3095

  72. {4,5,6,8,5,10}

    Returns: 3231

  73. {2,3,3,10,5,5}

    Returns: 9516

  74. {3,3,7,3,8,10}

    Returns: 6462

  75. {1000, 1000, 1000, 1000, 1000, 1000 }

    Returns: 6271

  76. {1000, 999, 998, 997, 996, 995 }

    Returns: 918


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: