Problem Statement
Cat Taro has the following building blocks: unit cubes of different colors (none of them black) and black rectangular prisms with dimensions 2x1x1. The number of cubes of each color is given as a
Taro is using the blocks to build w adjacent towers of blocks (some possibly empty), as shown on the right side of the picture below. Taro will always place the rectangular prisms vertically. In other words, each prism will look like two black unit cubes placed one on top of the other. Taro is not required to use all of the blocks when building the towers. However, he must use at least one block (a cube or a prism).

Rabbit Hanako is looking at Taro's towers from the left side of the room. To him, the towers seem as a single tower, as shown on the left side of the picture above. More precisely, at each height i Hanako sees the color of the block at height i in the leftmost tower that has such a block. Hanako's view can be described as a sequence of colors, giving the colors of each 1x1 square seen by Hanako in the order from bottom to top.
Taro and Hanako now wonder how many different non-empty views can Hanako see. (Two views are different if either their heights differ, or for some height the colors seen at that height differ.) You are given the
Definition
- Class:
- SkewedPerspective
- Method:
- countThem
- Parameters:
- int[], int, int
- Returns:
- int
- Method signature:
- int countThem(int[] cubes, int B, int w)
- (be sure your method is public)
Constraints
- w will be between 1 and 8, inclusive.
- cubes will contain between 0 and 50 elements, inclusive.
- Each element of cubes will be between 1 and 50, inclusive.
- The total sum of the elements of cubes will be between 0 and 50, inclusive.
- B will be between 0 and 10, inclusive.
Examples
{1,1}
1
2
Returns: 19
The 19 possible views are:
{1}
1
2
Returns: 5
{1}
3
2
Returns: 19
The 19 possible views are:
{}
5
5
Returns: 5
As we only have black prisms, each possible view will only contain black squares. The five possible views have heights 2, 4, 6, 8, and 10.
{1}
5
5
Returns: 39
{7,7,7}
0
8
Returns: 301226488
{50}
10
8
Returns: 665146241
{}
0
8
Returns: 0
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
10
8
Returns: 199658209
{9}
2
6
Returns: 466
{5,14,13}
7
3
Returns: 781975497
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
2
5
Returns: 463846336
{1,1,1,1,2,1,1,1,1,1}
0
1
Returns: 54745760
{1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1}
8
3
Returns: 714102776
{6,8,6,6,11,10}
7
6
Returns: 596093234
{4,3,4,2,3,2,6}
6
3
Returns: 961213759
{}
9
2
Returns: 9
{1,1,5,2,1,1}
8
2
Returns: 749928331
{1,1,1,2,1,2,2,1,2}
0
6
Returns: 85424462
{1,4,4,2,2,5,3,2,4,5,9}
10
7
Returns: 980637931
{1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2}
6
3
Returns: 708257516
{1,2,3,1,2,1,1,1,1,2,1,1,1,1,2,1,2}
1
7
Returns: 104938810
{11,9}
7
1
Returns: 623714550
{4,4,3,3,4,2,1,1,5,2,2}
9
7
Returns: 146505796
{3,6,3,5,3,3,8,5,3,3}
8
8
Returns: 641146404
{1,1,1,2,1,1,1}
9
2
Returns: 711012050
{30}
1
7
Returns: 766
{1,1,2,1,2,1}
0
4
Returns: 28394
{14,19}
7
5
Returns: 343636261
{9,6}
0
7
Returns: 19446
{7,5}
0
6
Returns: 3001
{15}
3
1
Returns: 4843
{3,5,3,4,3,2,2,4,7,1,2,2}
8
4
Returns: 533545918
{1}
5
6
Returns: 39
{1,1,1,2,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,2,1,1,1,2,1,1,1,1,1,2,1,1,1,1}
1
6
Returns: 213715583
{3,1,1,1,1}
4
5
Returns: 1329373
{4,5,3,7,4,1,4,6,3}
5
8
Returns: 321440342
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
4
6
Returns: 693702988
{1,2,1,1,1,1,1,2,3,2,1,1,2,1,1,1,1}
0
7
Returns: 884124802
{1,1,1,1,1,1,2,1,4,3,1,1,2,1,2,1,1,1,1,1,1,3,1,2,2,4,1,2,2,2,1,1}
8
7
Returns: 381101131
{12,7,9,4,5,4,6}
8
8
Returns: 815292690
{1,1,1,1,1,1,1,3,1,1,1,1,2,1,1,1,1,1,1,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,1,1,1,1,1,1}
9
7
Returns: 255805890
{5,4,6,4,3,6,3,8,5,5}
10
8
Returns: 86736258
{1,2,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,2,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1}
8
6
Returns: 48780676
{2,3,2,2,2,2,2,2,1,3,2,1,2,1,1,1,4,3,2,2,2,3,1,3}
8
6
Returns: 613817336
{2,1,2,1,2,2,1,2,2,1,2,1,3,2,1,1,3,5,3,1,2,3,2,4}
9
6
Returns: 391085551
{48}
8
8
Returns: 74306940
{5,5,4,6,5,3,2,2,3,2,2,3,3,3}
9
7
Returns: 873288870
{5,5,3,4,6,5,4,5,3,7}
8
6
Returns: 893462985
{1,1,1,2,1,1,2,2,1,1,1,1,2,2,1,2,1,1,1,2,1,1,2,1,1,1,1,1,2,1,2,2,1,1,2,1,2}
8
8
Returns: 116041219
{9,2,5,7,3,7,5,4,5}
8
7
Returns: 294257410
{4,4,5,5,3,1,7,4,4,2,5,3}
8
6
Returns: 536269216
{1,1,1,1,1,1,1,2,1,1,1,2,1,1,2,1,1,1,1,1,1,1,1,1,2,1,1,1,1,2,1,1,1,2,1,2,1,2,1,1,1,1}
10
7
Returns: 635889977
{1,1,2,1,1,1,1,1,1,2,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,2,1,1}
8
7
Returns: 666012396
{1,2,2,2,1,2,3,2,1,4,1,2,3,2,3,2,4,1,2,3,2,1,2,2}
8
6
Returns: 944297422
{2,2,4,6,4,6,6,4,4,3,7}
10
7
Returns: 90058018
{4,6,1,6,3,6,6,3,3,3,2,6}
10
8
Returns: 730997197
{1,1,1,1,1,2,1,1,1,1,3,2,1,1,2,1,1,2,2,1,2,2,3,1,2,2,1,2,1,2,2}
8
6
Returns: 515614360
{4,3,3,5,3,2,2,3,2,5,7,4,2,3}
10
6
Returns: 285724132
{19,15,13}
9
6
Returns: 837858978
{3,1,3,1,1,2,3,1,2,3,1,2,1,1,1,2,1,1,1,2,3,2,2,1,2,1,3}
10
6
Returns: 91107239
{2,1,2,2,1,3,3,2,2,1,2,2,2,3,1,1,3,3,2,2,1,3,2,1,2}
8
6
Returns: 153001281
{3,5,3,4,5,8,3,2,4,5,7}
9
8
Returns: 543039460
{2,2,2,1,1,2,1,1,1,1,2,2,1,1,2,2,2,1,2,1,1,2,3,1,1,2,3,1,2,2,1,1}
10
7
Returns: 660743297
{5,3,3,4,2,3,2,1,2,1,6,5,1,3,6,3}
10
7
Returns: 697332112
{1,1,1,1,1,1,1,2,2,1,1,1,2,2,3,2,1,2,1,1,2,1,2,3,2,2,2,2,3,2,1}
10
6
Returns: 928264524
{1,1,2,1,1,1,1,1,1,1,1,1,1,2,2,2,1,1,1,1,2,1,1,2,1,1,2,2,1,1,1,1,1,1,3,1,1,1}
8
7
Returns: 71101185
{1,2,1,1,1,1,1,2,1,2,2,1,1,2,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,3,1,1,1,1,2,1,1,1}
8
8
Returns: 544298185
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
8
6
Returns: 612335076
{13,15,20}
10
7
Returns: 928928653
{9,12,16,12}
10
6
Returns: 434969858
{49}
9
6
Returns: 866142378
{11,12,8,11,8}
9
6
Returns: 723160955
{23,24}
10
6
Returns: 998444265
{48}
10
8
Returns: 54212496
{47}
10
8
Returns: 295134152
{14,8,15,13}
8
7
Returns: 947862298
{17,30}
9
7
Returns: 266773690
{24,23}
8
7
Returns: 402659957
{22,27}
8
7
Returns: 340209833
{19,22,7}
9
6
Returns: 889690034
{12,17,13,6}
8
8
Returns: 887875834
{48}
8
8
Returns: 74306940
{25,23}
9
8
Returns: 223700040
{21,28}
10
7
Returns: 323740073
{9,12,11,17}
10
6
Returns: 258095153
{47}
10
8
Returns: 295134152
{47}
8
8
Returns: 600710387
{20,29}
9
6
Returns: 629629601
{10,11,8,13,8}
8
6
Returns: 8860112
{18,15,14}
8
6
Returns: 740007065
{5,16,11,9,6}
10
7
Returns: 950427230
{23,25}
9
7
Returns: 223696456
{8,7,8,14,12}
8
8
Returns: 418822026
{13,10,10,8,7}
9
6
Returns: 263851329
{49}
10
8
Returns: 949155103
{47}
9
8
Returns: 651924767
{23,24}
8
8
Returns: 402660085
{15,14,18}
8
7
Returns: 266834995
{1}
2
2
Returns: 11
{1}
1
1
Returns: 4
{10, 8, 10, 5, 3, 3, 1, 2, 3, 4 }
10
8
Returns: 627459486
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
10
8
Returns: 199658209
{2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
10
8
Returns: 839270363
{1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 1, 2 }
10
8
Returns: 7792819
{4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }
10
8
Returns: 901388560