Problem J
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 23 Accepted Submission(s) : 8
Problem Description
有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行。请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数。<br>其中,蜂房的结构如下所示。<br><img src=../data/images/C40-1001-1.jpg><br>
Input
输入数据的第一行是一个整数N,表示测试实例的个数,然后是N 行数据,每行包含两个整数a和b(0<a<b<50)。<br>
Output
对于每个测试实例,请输出蜜蜂从蜂房a爬到蜂房b的可能路线数,每个实例的输出占一行。<br>
Sample Input
2
1 2
3 6
Sample Output
1
3
===========================
还是斐波那契数列,注意数组开成long long就好了。。。。。。
AC代码:
#include<bits/stdc++.h>
using namespace std;
long long f[101];//注意数据类型;
int main()
{
int t;
cin>>t;
while(t--)
{
memset(f,0,sizeof(f));
int x,y;
cin>>x>>y;
f[x]=1;f[x+1]=1;f[x+2]=2;//多写了一个状态。。。
for(int i=x+3;i<=y;++i)f[i]=f[i-1]+f[i-2];
cout<<f[y]<<endl;
}
return 0;
}
The end;