Problem Statement
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, 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.
{1, 2, 3}
1000
Returns: 6
Here you can swap any two adjacent wolves. Thus, all 3! = 6 permutations are possible.
{1, 2, 3}
4
Returns: 3
You can get {1, 2, 3}, {2, 1, 3} and {2, 3, 1}.
{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.
{2,4,6,1,3,5}
8
Returns: 60
{1000}
1000
Returns: 1
{212,263,494}
90
Returns: 1
{807}
500
Returns: 1
{83}
5
Returns: 1
{206}
35
Returns: 1
{228,51}
565
Returns: 2
{189,266}
186
Returns: 1
{234,241,195,15}
557
Returns: 24
{11,13,1,28,24}
1
Returns: 1
{479,756,370,386,312}
903
Returns: 6
{49,4}
22
Returns: 1
{58,75,177,85,125,63}
239
Returns: 36
{417,112,334,236,445}
1000
Returns: 120
{75,53,43,209,93}
459
Returns: 120
{93,104,126,79,4,144}
221
Returns: 72
{56,258,84,543}
114
Returns: 1
{696,246,21,617}
276
Returns: 2
{3,3,4}
11
Returns: 6
{20,90,138,21,109,121}
165
Returns: 30
{63,142,577,170}
36
Returns: 1
{187,221,184,50,141}
158
Returns: 1
{79,110,26,206}
367
Returns: 24
{185,213,470,79,410,230}
341
Returns: 1
{67,127,163,267,576}
949
Returns: 120
{739,197,952,292,521}
107
Returns: 1
{706,98,748,22,535}
135
Returns: 1
{134,130,717,519}
720
Returns: 2
{25,16,22,21}
29
Returns: 1
{337,268}
192
Returns: 1
{228}
572
Returns: 1
{543,548,567}
414
Returns: 1
{12,4,37,29}
114
Returns: 24
{7,272,296,87,152}
64
Returns: 1
{7,3}
9
Returns: 1
{461}
903
Returns: 1
{226,349}
919
Returns: 2
{95,97}
156
Returns: 1
{373,173,91,338}
754
Returns: 24
{441,410,236,177,348,346}
24
Returns: 1
{127,95,246,120,165}
48
Returns: 1
{61,58,17,65,7}
49
Returns: 1
{204,481}
161
Returns: 1
{17,75,85,80,14}
123
Returns: 20
{42,128}
18
Returns: 1
{651,134,452,329,515,616}
780
Returns: 5
{245,138,159}
481
Returns: 6
{145}
876
Returns: 1
{360,408,294}
24
Returns: 1
{709,776,736,307}
693
Returns: 1
{569,554}
514
Returns: 1
{204,188,263,209}
35
Returns: 1
{502, 499, 498, 503, 102, 899 }
1000
Returns: 15
{2, 4, 6, 1, 3, 5 }
8
Returns: 60
{2, 1, 3, 3, 1, 2 }
5
Returns: 360
{1, 1, 1, 1, 1, 1 }
5
Returns: 720
{2, 1, 3, 3, 1, 3 }
1000
Returns: 720
{1, 1, 1, 1, 1, 1 }
1
Returns: 1
{1, 1, 2, 1, 1 }
2
Returns: 4
{1, 1 }
1
Returns: 1
{4 }
2
Returns: 1
{1, 2, 3 }
4
Returns: 3
{2, 1, 3 }
4
Returns: 3
{1, 2, 3, 4, 5, 6 }
6
Returns: 15