Problem Statement
Sophie likes to build structures. She always takes all the blocks and builds a structure according to the following steps: She places the blocks one at a time, in any order she likes. When placing a block, she may either put it on the floor, or directly on top of a single previously placed block. Hence the final structure can be viewed as a collection of towers, each consisting of one or more blocks placed atop each other. Note that Sophie's structure always contains all the available blocks.
Additionally, Sophie follows one more rule: She always places the blocks in such a way that for each color, all blocks of that color share the same height. Josh likes to take Sophie's structure apart. He also does that in steps. In each step, Josh removes all blocks of a particular color. However, he may only remove a block if no other block is currently placed on top of it.
Given one of Sophie's structures, a permutation of colors is called valid if it represents an order in which Josh can remove the blocks. Sometimes, some permutations of colors are not valid. For example, if Sophie placed a block of color 3 on top of a block of color 0, the permutations where 0 occurs before 3 are not valid.
Sophie and Josh now play the following game: First, Sophie builds a structure according to her rules. Next, Josh counts how many permutations of colors are valid for the structure she built.
Two structures built by Sophie are called fundamentally different if there are colors i and j such that in one structure there is at least one block of color i placed directly on top of a block of color j, and in the other structure there is no such pair of blocks.
You are given a
Definition
- Class:
- CosmicBlocks
- Method:
- getNumOrders
- Parameters:
- int[], int, int
- Returns:
- int
- Method signature:
- int getNumOrders(int[] blockTypes, int minWays, int maxWays)
- (be sure your method is public)
Notes
- Please read the definition of fundamentally different structures carefully. There may be pairs of structures that look different to you, but are not fundamentally different according to our definition.
Constraints
- blockTypes will contain between 1 and 6 elements, inclusive.
- Each element of blockTypes will be between 1 and 7,500, inclusive.
- minWays will be between 1 and 720, inclusive.
- maxWays will be between minWays and 720, inclusive.
Examples
{2,2,2}
1
1
Returns: 6
Sophie wants to build a structure such that there is only one valid permutation of colors. To do so, she must put different colors into different heights. Each permutation of the colors produces a different structure, so there are 3! = 6 such structures.
{1,1,1,1,1,1}
720
720
Returns: 1
There is only one way to place the blocks such that they can be removed in any order.
{2,2}
1
2
Returns: 3
Sophie has three ways how to build her structure: Place all the blocks on the floor. Place each block of color 0 on top of one block of color 1. Place each block of color 1 on top of one block of color 0.
{1,2}
1
2
Returns: 2
In this case there is only one block of color 0 and two blocks of color 1, so it is impossible to put blocks of color 1 on top of blocks of color 0.
{1}
1
1
Returns: 1
{1,2,4,8}
5
30
Returns: 27
{1,2,4,8,16,32}
1
720
Returns: 4348
{1500,1500,1500,1500,1500,7500}
1
720
Returns: 11963
{7500,7500,7500,7500,7500,7500}
1
720
Returns: 14202
{7500,3750,1875,937,468,200}
1
720
Returns: 8110
{1,2,1,2,3,9}
1
720
Returns: 3180
{1,1,8,8,27,27}
1
720
Returns: 3198
{2, 5132, 5981}
624
641
Returns: 0
{372, 2784, 790}
138
467
Returns: 0
{5472, 4987, 3903, 5033, 5762, 6908}
282
710
Returns: 15
{30,30,60,120,240,480}
1
720
Returns: 8499
{30,30,60,120,240,480}
360
360
Returns: 16
{30,30,60,120,240,480}
180
180
Returns: 112
{30,30,60,120,240,480}
45
45
Returns: 54
{653}
1
403
Returns: 1
{6049}
1
410
Returns: 1
{3594}
1
146
Returns: 1
{2768}
1
632
Returns: 1
{1190}
1
304
Returns: 1
{4400}
1
406
Returns: 1
{3840, 4758}
1
199
Returns: 2
{5563, 2440}
1
96
Returns: 2
{4179, 6315}
1
553
Returns: 2
{2684, 4685}
1
605
Returns: 2
{2847, 4315}
1
706
Returns: 2
{1791, 4451}
1
81
Returns: 2
{6558, 4968, 4052}
1
378
Returns: 8
{889, 2759, 5658}
1
69
Returns: 8
{64, 6978, 6970}
1
56
Returns: 8
{6211, 4589, 401}
1
661
Returns: 8
{2186, 4938, 758}
1
393
Returns: 8
{2448, 6574, 7103}
1
337
Returns: 8
{6010, 2692, 2469, 59}
1
110
Returns: 52
{1203, 3691, 4140, 2890}
1
39
Returns: 49
{4570, 442, 4421, 1796}
1
150
Returns: 49
{3132, 6982, 152, 4390}
1
328
Returns: 50
{535, 131, 5069, 3947}
1
71
Returns: 52
{3346, 6404, 4982, 2542}
1
249
Returns: 49
{7363, 1429, 6780, 3180, 2675}
1
402
Returns: 498
{2765, 2674, 2225, 7025, 6118}
1
688
Returns: 501
{6124, 5410, 2565, 4659, 1611}
1
508
Returns: 501
{1692, 6684, 3177, 1009, 1313}
1
484
Returns: 538
{4925, 1900, 3561, 7444, 1724}
1
147
Returns: 516
{2836, 5221, 3228, 2841, 6049}
1
376
Returns: 520
{7186, 2891, 1984, 3400, 5837, 6100}
1
646
Returns: 7865
{397, 1378, 6648, 5841, 5335, 3708}
1
660
Returns: 7637
{6451, 3210, 704, 1393, 3470, 5670}
1
318
Returns: 7522
{3908, 6514, 149, 2131, 2703, 2476}
1
558
Returns: 7871
{4134, 4114, 5897, 5591, 2230, 3414}
1
482
Returns: 8135
{1224, 4826, 1923, 3428, 3711, 6468}
1
279
Returns: 7819
{1,2,3,4,5,6}
1
720
Returns: 4445
{7500,1000,7500,1000,7500}
8
88
Returns: 448
{7500,1000,7500,1000,7500,1000}
1
720
Returns: 9242
{300,400,699,1098,999,7500}
1
720
Returns: 8585
{8,88,888,888,88,8}
1
30
Returns: 3227
{9,18,26,35,44,53}
1
720
Returns: 8146
{7500, 7499, 7498, 7497, 7496, 7495 }
1
720
Returns: 8195