zoukankan      html  css  js  c++  java
  • B

    Description

    有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行。请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数。 
    其中,蜂房的结构如下所示。 

    Input

    输入数据的第一行是一个整数N,表示测试实例的个数,然后是N 行数据,每行包含两个整数a和b(0<a<b<50)。 

    Output

    对于每个测试实例,请输出蜜蜂从蜂房a爬到蜂房b的可能路线数,每个实例的输出占一行。 

    Sample Input

    2
    1 2
    3 6

    Sample Output

    1
    3
    题解:因为蜂房的特殊结构,1到n的步数和k+1到n+k的步数是相等的
    所以用dp[n-1]来储存步数。
    dp[i] = dp[i-1] + dp[i-2];(i大于2);
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<stdlib.h>
    #include<vector>
    #include<queue>
    #include<cmath>
    using namespace std;
    #define maxn 100
    #define oo 0x3f3f3f
    #define PI 3.1415926535897932
    int n;
    int k;
    long long dp[maxn];
    void init()
    {
        for(int i=3; i<=maxn; i++)
            dp[i] = dp[i-1] + dp[i-2];
    }
    int main()
    {
        int t;
        scanf("%d", &t);
    
        dp[1] = 1;
        dp[2] = 2;
        while(t--)
        {
            init();
            int m,n;
            scanf("%d%d",&m,&n);
    
            k = n - m;
            printf("%I64d
    ",dp[k]);
    
    
        }
        return 0;
    }
  • 相关阅读:
    140704
    140703
    140702
    堆排序
    并查集
    140701
    这年暑假集训-140630
    vim for python
    hihocode 第九十二周 数论一·Miller-Rabin质数测试
    hdu 3157 Crazy Circuits 有源汇和下界的最小费用流
  • 原文地址:https://www.cnblogs.com/biu-biu-biu-/p/5744488.html
Copyright © 2011-2022 走看看