本文依旧是动态规划的题,杭电的2501题。
3 2 8 12
3 171 2731
import java.util.Scanner;
public class Main {
public static void main(String[] args){
long f[] =new long[51];
f[1]=1;
f[2]=3;
for(int i=3;i<51;i++)
{
f[i]=f[i-1]+2*f[i-2];
}
Scanner sc=new Scanner(System.in);
int t=Integer.valueOf(sc.nextLine());
while((t--)!=0)
{
int a=sc.nextInt();
System.out.println(f[a]);
}
}
}3 171 2731
462



被折叠的 条评论
为什么被折叠?



