Description
There are n cells in a sequence. You can use three kinds of colors, red , pink , green to paint these cells , one cell with only one kind of color . Promising that any two adjacent cells are painted with different colors and the color in the first cell is different from the color in the last cell . Now you need to calculate the total number of methods, meeting the given requirements, to paint these n cells.
Input
There are several test cases. Each test case is in one line with a integer N. (0 < n <= 50)
Output
For each test case, output the total number of the methods that meet the requirements. One answer a line , respectively.
Sample Input
1
2
Sample Output
3
6
package OJ;
import java.util.*;
public class P10_temp {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
ArrayList<Integer> al = new ArrayList<Integer>();
while(true){
// if(in.hasNextInt()){
int n = in.nextInt();
int num1 = 1; //这一层为1的结点数
int num = 0; //这一层的结点数
if(n == 1){
// al.add(3);
System.out.println(3);
}
else{
for(int i=1; i<=n; i++){
if(i == 1){
num1 = 1;
num = 1;
}
else{
num1 = num - num1;
num = num * 2;
}
}
// al.add((num - num1)*3);
System.out.println((num - num1)*3);
}
// }
// else
// break;
}
// for(int i : al){
// System.out.println(i);
// }
}
}