5、蜜蜂路线

5、蜜蜂路线
【问题描述】
        一只蜜蜂在下图所示的数字蜂房上爬动,已知它只能从标号小的蜂房爬到标号大的相邻蜂房,现在问你:蜜蜂从蜂房M开始爬到蜂房N,M<N,有多少种爬行路线?
 
【输入格式】
 输入M,N的值。
【输出格式】
 爬行有多少种路线。
【输入样例】bee.in
   1  14
【输出样例】bee.out
   377
 
 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4 int main()
 5 {
 6     __int64  f[60];
 7     int a,b,c;
 8     scanf("%d %d",&a,&b);
 9         f[a]=0;//将a的初值赋值为0; 
10         f[a+1]=1;//下一步赋值为1; 
11         f[a+2]=2;//赋值为2; 
12         if(b-a==1)//若a==b,cout<<1; 
13             printf("1
");
14         else
15         {
16            for(int i=a+3;i<=b;i++)
17                f[i]=f[i-1]+f[i-2];//第i个=前两个之和; 
18            printf("%d
",f[b]);
19         }
20     return 0;
21 }
原文地址:https://www.cnblogs.com/lyqlyq/p/6598772.html