HDU-2044-一只小蜜蜂

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

题意:

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

思路:

刚开始按位置递推,后来发现是按照距离递推。

代码:

#include <iostream>
#include <memory.h>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <queue>
#include <string>
#include <stack>
#include <iterator>

using namespace std;

typedef long long LL;

const int MAXN = 60;

LL a[MAXN];

int main()
{
    a[1] = 1;
    a[2] = 2;
    for (int i = 3;i <= 50;i++)
        a[i] = a[i - 1] + a[i - 2];
    int t;
    cin >> t;
    while (t--)
    {
        int l, r;
        cin >> l >> r;
        cout << a[r - l] << endl;
    }

    return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/YDDDD/p/10639956.html