zoukankan      html  css  js  c++  java
  • HDU 2044 一只小蜜蜂 *

    一只小蜜蜂...

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 75895    Accepted Submission(s): 27245


    Problem 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

    第一遍

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    #define maxn 56
    int main()
    {
        int n,dp[maxn],m,T;
        while(cin >> T){
            while(T--){
                cin >> n >> m;
                dp[n] = 1;
                dp[n+1] = 1;
                for(int i=n+2;i<=m;i++){
                    dp[i] = dp[i-1] + dp[i-2];
                }
                cout << dp[m] << endl;
            }
        }
        return 0;
    }

    好好考虑两个的区别

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    #define maxn 56
    int main()
    {
        int n,m,T;
        long long dp[maxn];
        dp[1] = 1;
        dp[2] = 1;
        for(int i=3;i<=55;i++){
            dp[i] = dp[i-1] + dp[i-2];//向右走时如果m比n大2的时候有两条路
        }
        while(cin >> T){
            while(T--){
                cin >> n >> m;
                cout << dp[m-n+1] << endl;
            }
        }
        return 0;
    }
    彼时当年少,莫负好时光。
  • 相关阅读:
    Extension Methods (C# Programming Guide)
    ArraySegment
    git config
    0.0.0.0 IPAddress.Any 【】127.0.0.1 IPAddress.Loopback 【】localhost
    public static float CompareExchange(ref float location1,float value,float comparand)
    ConcurrentDictionary中的 TryRemove
    enum类型
    Array.Copy vs Buffer.BlockCopy
    伴随待字闺中的生命周期分析
    Twitter实时搜索系统EarlyBird
  • 原文地址:https://www.cnblogs.com/l609929321/p/7218389.html
Copyright © 2011-2022 走看看