ACMSTEP 3.1.2 一只小蜜蜂 //递推

时间:2022-09-19 15:21:23

原题链接


也是一道递推题 递推公式为 a[i] = a[i-1] + a[i-2]
但是a[1] =1,a[2] = 2;很像斐波那契数列。


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
long long a[60];
void make()
{
	int i;
	a[1]=1;
	a[2]=2;
	for (i=3; i<=50; i++)
	{
		a[i] = a[i-1] + a[i-2];
	}
}

using namespace std;
int main()
{
	int cases, a1, b1;
	make();
	cin>>cases;
	while (cases--)
	{
		cin>>a1>>b1;
		cout<<a[b1-a1]<<endl;
	}
	return 0;
}