1268 蜜蜂搬家
来源:互联网 发布:家用果蔬臭氧机 知乎 编辑:程序博客网 时间:2024/04/28 15:28
有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行。如图。
试求蜜蜂从蜂房a爬到蜂房b的可能路线数。
- 输入
第一行一个整数表示数据组数(多组数据),对于每组数据只一行有两个整数a,b (1≤a < b≤40)
- 输出
对于每组输入,输出一行,即从蜂房a爬到蜂房b的可能路线数。
- 样例输入
11 5
- 样例输出
5
找规律求解,有叠加的过程
#include<stdio.h>int temp1;int temp2;main(){int m,n,t,i;double upset[1000];int number,te;int a,b;scanf("%d",&number);for(te=1;te<=number;te++){ m=2; scanf("%d %d",&a,&b); n=b-a-1; temp1=m; temp2=n; upset[0]=1; for(i=1;i<=temp1;i++) upset[i]=i+1; if(temp2<=temp1) { for(i=1;i<=temp2;i++) upset[i]=i+1; printf("%.0lf\n",upset[temp2]); } if(temp2>temp1) { for(i=temp1+1;i<=temp2;i++) upset[i]=upset[i-1]+upset[i-temp1]; printf("%.0lf\n",upset[temp2]); }}}