递推
View Code
import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
public static void main(String args[])
{
Scanner cin = new Scanner(new BufferedInputStream(System.in));
BigInteger[][] f = new BigInteger[101][3];
f[0][0] = new BigInteger("0");
f[0][1] = new BigInteger("1");
f[0][2] = new BigInteger("0");
BigInteger[] res = new BigInteger[101];
for (int i = 1; i <= 100; i++)
{
f[i][0] = f[i - 1][0].add(f[i - 1][2]);
f[i][1] = f[i - 1][1].add(f[i - 1][2]).add(f[i - 1][0]);
f[i][2] = f[i - 1][1].add(f[i - 1][2]).add(f[i - 1][0]);
res[i] = f[i][0].add(f[i][2]);
}
while (cin.hasNext())
{
int a = cin.nextInt();
System.out.println(res[a]);
}
}
}
import java.util.*;
import java.math.*;
public class Main {
public static void main(String args[])
{
Scanner cin = new Scanner(new BufferedInputStream(System.in));
BigInteger[][] f = new BigInteger[101][3];
f[0][0] = new BigInteger("0");
f[0][1] = new BigInteger("1");
f[0][2] = new BigInteger("0");
BigInteger[] res = new BigInteger[101];
for (int i = 1; i <= 100; i++)
{
f[i][0] = f[i - 1][0].add(f[i - 1][2]);
f[i][1] = f[i - 1][1].add(f[i - 1][2]).add(f[i - 1][0]);
f[i][2] = f[i - 1][1].add(f[i - 1][2]).add(f[i - 1][0]);
res[i] = f[i][0].add(f[i][2]);
}
while (cin.hasNext())
{
int a = cin.nextInt();
System.out.println(res[a]);
}
}
}