一只小蜜蜂...Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 93472 Accepted Submission(s): 33285 http://acm.hdu.edu.cn/showproblem.php?pid=2044 Problem Description 有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行。请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数。
Input 输入数据的第一行是一个整数N,表示测试实例的个数,然后是N 行数据,每行包含两个整数a和b(0<a<b<50)。
Output 对于每个测试实例,请输出蜜蜂从蜂房a爬到蜂房b的可能路线数,每个实例的输出占一行。
Sample Input 2 1 2 3 6
Sample Output 1 3 |
注意:用long long啊!!
思路:就是斐波那契
以2-6为例:就是找6中2的个数
蜂房 1 2 3 4 5
个数 0 1 1 2 3
即:从2号蜂房开始有2,有1条路
2到3号蜂房有1条路
2到4号蜂房有(2到2)+(3到2)的路
......
代码:
#include<iostream>
using namespace std;
long long dp[55];
int main()
{
int n;
cin>>n;
int a,b;
dp[1]=0;
dp[2]=1;
dp[3]=2;
for(int i=4;i<=50;i++)
dp[i]=dp[i-1]+dp[i-2];
while(n--)
{
int a,b;
cin>>a>>b;
cout<<dp[b-a+1]<<endl;
}
return 0;
}