http://acm.hdu.edu.cn/showproblem.php?pid=2047
也是倒推,a[i] = 2*(a[i-1]+a[i-2])
1 #include<iostream> 2 #include<cmath> 3 #include<algorithm> 4 using namespace std; 5 6 7 int main() 8 { 9 int n; 10 while(cin>>n && n) 11 { 12 long long a[50]; 13 a[1] = 3; 14 a[2] = 8; 15 for(int i = 3;i<=n;i++) 16 a[i] = 2*(a[i-1]+a[i-2]); 17 cout<<a[n]<<endl; 18 } 19 20 }