一只小蜜蜂…
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 94823 Accepted Submission(s): 33801
Problem Description
有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行。请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数。
其中,蜂房的结构如下所示。
Input
输入数据的第一行是一个整数N,表示测试实例的个数,然后是N 行数据,每行包含两个整数a和b(0
Output
对于每个测试实例,请输出蜜蜂从蜂房a爬到蜂房b的可能路线数,每个实例的输出占一行。
Sample Input
2
1 2
3 6
Sample Output
1
3
Author
lcy
Source
Code
这是一道递归求解题
#include <iostream>
using namespace std;
const int maxn = 50 + 5;
long long array[maxn];
int main()
{
freopen("in.txt", "r", stdin);
array[1] = 1;
array[2] = 2;
for(int i = 3; i <= maxn; i++)
array[i] = array[i - 1] + array[i - 2];
int n;
cin >> n;
while(n--)
{
int a, b;
cin >> a >> b;
cout << array[b - a] << endl;
}
return 0;
}
/*
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 50 + 5;
bool used[maxn] = {0};
int array[maxn], ans = 0;
void bfs(int now, int flag);
int main()
{
int n;
scanf("%d", &n);
while(n--)
{
int a, b;
scanf("%d %d", &a, &b);
if(!used[b - a])
{
ans = 0;
bfs(0, b - a);
array[b - a] = ans;
used[b - 1] = 1;
}
cout << array[b - a] << endl;
}
return 0;
}
void bfs(int now, int flag)
{
if(now == flag)
{
ans++;
return;
}
if(now < flag)
{
bfs(now + 1, flag);
bfs(now + 2, flag);
}
}
*/