思路:dp[i]=3*dp[i-3]+2*(dp[i-4]+dp[i-6]+...+dp[2]+dp[0]);
import java.math.BigDecimal; import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner cin=new Scanner(System.in); long dp[]=new long[31]; long sum[]=new long[31]; dp[0]=1; dp[1]=0; dp[2]=3; dp[3]=0; sum[0]=1; sum[2]=4; for(int i=4;i<31;i++) { dp[i]=3*dp[i-2]+2*sum[i-4]; if(i%2==0) sum[i]=dp[i]+sum[i-2]; } while(cin.hasNext()) { int n=cin.nextInt(); if(n==-1) break; System.out.println(dp[n]); } } }