Problem Statement
A farmer is planting a line of trees across the front of his house. He has four different kinds of trees he would like to plant. However, for aesthetic reasons, he does not want two of the same type of tree next to each other. Beyond that, any arrangement of trees is considered acceptable.
You are given
Definition
- Class:
- TreeSpreading
- Method:
- countArrangements
- Parameters:
- int, int, int, int
- Returns:
- long
- Method signature:
- long countArrangements(int a, int b, int c, int d)
- (be sure your method is public)
Notes
- Each tree of a given type is identical to others of the same type, thus swapping the positions of two of the same type of tree does not consitute a new arrangement.
Constraints
- a, b, c, and d will be between 0 and 10, inclusive.
Examples
1
1
0
0
Returns: 2
There are only two trees to place, and they can go in either order.
2
2
0
0
Returns: 2
There are two possible arrangements: ABAB or BABA. Any others have two identical trees adjacent to one another.
1
1
1
1
Returns: 24
Since all four trees are different, they can be arranged in any order, so the answer is 4!.
3
2
1
1
Returns: 96
10
10
10
10
Returns: 174702663548149248
5
1
1
1
Returns: 0
9
10
8
7
Returns: 173887297986990
1
2
3
4
Returns: 1074
5
6
7
8
Returns: 33170046582
9
10
10
8
Returns: 5475644741386140
3
4
7
9
Returns: 71903316
7
8
9
10
Returns: 173887297986990
9
7
5
4
Returns: 2552333100
10
9
7
5
Returns: 2161729439448
10
8
7
1
Returns: 78434892
9
6
3
0
Returns: 504
0
0
0
0
Returns: 1
10
10
10
10
Returns: 174702663548149248
0
0
0
0
Returns: 1