2016SDAU编程练习三1011

来源:互联网 发布:java写客户端程序 编辑:程序博客网 时间:2024/05/22 10:41

Problem K 


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

思路:DP长得都比较像搜索,但比搜索好写多了,套一下就行(这个蜂房长什么样他也没说清。。。)
感想:有挺多题长的还是差不多的
AC代码:
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
    long long int a,T,n,m,i,j,temp,k,b;
    long long int map[60];
    map[0]=1;
    map[1]=1;
    for(i=2;i<55;i++)
        map[i]=map[i-1]+map[i-2];
    cin>>T;
    while(T--)
    {
        scanf("%d%d",&a,&b);
        //cout<<a<<b<<endl;
        cout<<map[b-a]<<endl;
    }
    return 0;
}
0 0
原创粉丝点击