一只小蜜蜂...
Problem Description
有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行。请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数。 其中,蜂房的结构如下所示。
</pre><pre class="panel_title">Input
输入数据的第一行是一个整数N,表示测试实例的个数,然后是N 行数据,每行包含两个整数a和b(0<a<b<50)。
</pre><pre class="panel_title">Output
对于每个测试实例,请输出蜜蜂从蜂房a爬到蜂房b的可能路线数,每个实例的输出占一行。
</pre><pre class="panel_title">Sample Input
2 1 2 3 6
</pre><pre class="panel_title">Sample Output
1 3
</pre><pre class="panel_title">Author
lcy
</pre><pre class="panel_title">Source
递推求解专题练习(For Beginner)
</pre><pre class="cpp" name="code">
#include<cstdio>
#include<cstring>
__int64 f[60];
void fib()
{
int i;
memset(f,0,sizeof(f));
f[1]=1;
f[2]=1;
for(i=3;i<50;i++)
f[i]=f[i-1]+f[i-2];
}
int main()
{
int n,m,t;
fib();
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
printf("%I64d\n",f[m-n+1]);
}
return 0;
}
解析:此题是Fibonacci 数列,递推可得出结论,int 型是不够的,WA了一次;