http://acm.hdu.edu.cn/showproblem.php?pid=2046
和前面的一样,a[i] = 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[51]; 13 a[1] = 1; 14 a[2] = 2; 15 a[3] = 3; 16 for(int i = 4;i<=n;i++) 17 { 18 a[i] = a[i-1] + a[i-2]; 19 } 20 cout<<a[n]<<endl; 21 } 22 23 }