Problem Statement
A farmer wants to plant a row of trees along the front of his house. He has two different kinds of trees, some which are plain looking, and other, more expensive, fancy trees. He wishes to plant the trees in such a way that not all of the fancy trees are grouped together, so he insists that no two fancy trees be adjacent to one another.
You are given an
Definition
- Class:
- TreePlanting
- Method:
- countArrangements
- Parameters:
- int, int
- Returns:
- long
- Method signature:
- long countArrangements(int total, int fancy)
- (be sure your method is public)
Notes
- You may assume that each fancy tree is identical to one other, and likewise for the plain trees.
- If no valid arrangements are possible, the return value should be 0.
Constraints
- total will be between 1 and 60, inclusive.
- fancy will be between 1 and 60, inclusive.
- fancy will be less than or equal to total.
Examples
4
2
Returns: 3
Here, we have two plain trees, and two fancy trees. There are only three acceptable arrangements: PFPF, FPPF or FPFP. Any other arrangement would have two fancy trees next to each other.
3
1
Returns: 3
There is only one fancy tree, and it can go in any of three locations.
4
3
Returns: 0
There is no way to place all three fancy trees without two of them being next to each other.
10
4
Returns: 35
60
17
Returns: 686353797976
55
20
Returns: 7307872110
41
19
Returns: 8855
10
3
Returns: 56
55
35
Returns: 0
19
17
Returns: 0
58
21
Returns: 28781143380
45
20
Returns: 230230
36
12
Returns: 5200300
22
5
Returns: 8568
58
12
Returns: 52251400851
60
60
Returns: 0
60
59
Returns: 0
60
31
Returns: 0
60
30
Returns: 31
1
1
Returns: 1
2
2
Returns: 0
60
15
Returns: 511738760544
60
10
Returns: 12777711870
60
20
Returns: 269128937220
60
29
Returns: 4960
60
30
Returns: 31
60
22
Returns: 51021117810
3
2
Returns: 1
51
15
Returns: 9364199760
60
17
Returns: 686353797976
60
12
Returns: 92263734836
10
4
Returns: 35
59
20
Returns: 137846528820
60
25
Returns: 600805296
60
18
Returns: 608359048206
5
3
Returns: 1
9
5
Returns: 1
18
1
Returns: 18