HDU 2044 DP (fibonacci)

HDU 2044

https://vjudge.net/problem/HDU-2044

每一个只有可能由它左面的以及左上的状态变过来,也就是F(i-1)和F(i-2)

F(1) = 1

F(2) = 2

F(i) = F(i-1) +  F(i-2) (i>=3)

 AC 代码:

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <bits/stdc++.h>
 4 using namespace std;
 5 int main()
 6 {
 7     int n;
 8     int a,b;
 9     long long  DP[52];
10     DP[1] = 1;
11     DP[2] = 2;
12     for(int i = 3;i <= 51;i++)
13     {
14         DP[i] = DP[i-1] + DP[i-2];
15     }
16     cin >> n;
17     for(int i = 1;i <= n;i++)
18     {
19         cin >> a >> b;
20         cout<<DP[b-a]<<endl;
21     }
22     return 0;
23 }
24  

 

 

posted on 2019-07-14 16:50  Algorithm_Ethusiast  阅读(152)  评论(0编辑  收藏  举报

导航