Problem Statement |
| A string of letters A, B, C is forbidden if there are three consecutive letters from which one is A, one is B, and one is C. For example, BAACAACCBAAA is forbidden, while AABBCCAABB is not.
Your task is to calculate how many such strings of length n are not forbidden.
|
|
Definition |
| Class: | ForbiddenStrings | Method: | countNotForbidden | Parameters: | int | Returns: | long | Method signature: | long countNotForbidden(int n) | (be sure your method is public) |
|
|
|
|
Constraints |
- | n will be between 1 and 30, inclusive. |
|
Examples |
0) | |
| | Returns: 9 | All 9 strings of length 2 are not forbidden.
|
|
|
1) | |
| | Returns: 21 | There are 27 strings of length 3. Of these, 6 contain one occurrence of each letter. Those 6 strings are forbidden, so you should return 21.
|
|
|
2) | |
| |