HDU 2044.一只小蜜蜂【水题】【11月28】

来源:互联网 发布:华讯网络与华三 编辑:程序博客网 时间:2024/05/29 17:56

一只小蜜蜂

Problem Description
有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行。请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数。
其中,蜂房的结构如下所示。

 

Input
输入数据的第一行是一个整数N,表示测试实例的个数,然后是N 行数据,每行包含两个整数a和b(0<a<b<50)。
 

Output
对于每个测试实例,请输出蜜蜂从蜂房a爬到蜂房b的可能路线数,每个实例的输出占一行。
 

Sample Input
21 23 6
 

Sample Output
13
到n,知道到n-1和n-2的路径数就可以了。斐波那契数列:

#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cmath>#include <algorithm>using namespace std;int main(){    long long f[55];    f[1]=1;    f[2]=1;    for(int i=3;i<55;i++)        f[i]=f[i-1]+f[i-2];    int n,a,b;    cin>>n;    while(n--)    {        cin>>a>>b;        cout<<f[b-a+1]<<endl;    }    return 0;}


0 0
原创粉丝点击