http://acm.hdu.edu.cn/showproblem.php?pid=2190
考虑两种砖,得出递推公式。
a[i]=a[i-1]+2*a[i-2]
View Code
#include <stdio.h> int main() { int n,i; __int64 a[40]={0,1,3}; for(i=3;i<=30;i++) a[i]=a[i-1]+2*a[i-2]; scanf("%d",&n); while(n--) { scanf("%d",&i); printf("%I64d\n",a[i]); } return 0; }