hdu 2044 一只小蜜蜂...(简单dp)

一只小蜜蜂...

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

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

 1 //#define MY_DEBUG
 2
 3 #include <iostream>
 4 #include <cstdio>
 5 using namespace std;
 6
 7 int main()
 8 {
 9 #ifdef MY_DEBUG
10     freopen("./in.txt", "r", stdin);
11     //freopen("./out.txt", "w", stdout);
12 #endif // MY_DEBUG
13
14     __int64 fib[55];
15     fib[1] = 1;
16     fib[2] = 1;
17     int i;
18     for (i = 3; i < 50; ++i) {
19         fib[i] = fib[i - 1] + fib[i - 2];
20     }
21
22     int T, a, b;
23     scanf("%d", &T);
24
25     while (T--) {
26         scanf("%d%d", &a, &b);
27         printf("%I64d\n", fib[b - a + 1]);
28     }
29
30     return 0;
31 }
时间: 2024-08-03 15:23:45

hdu 2044 一只小蜜蜂...(简单dp)的相关文章

HDU 2044 一只小蜜蜂... 简单动态规划

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2044题目描述:有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行.请编程计算蜜蜂从蜂房a爬到蜂房b的可能路线数.其中,蜂房的结构如下所示. 输入数据的第一行是一个整数N,表示测试实例的个数,然后是N 行数据,每行包含两个整数a和b(0<a<b<50).对于每个测试实例,请输出蜜蜂从蜂房a爬到蜂房b的可能路线数,每个实例的输出占一行.题目分析:对于这道题目,给我a和b,求从蜂房a到蜂房b

hdu 2044 一只小蜜蜂... (java)

问题: 第一次用的int没能过,改成long就行了,每次不知道能否够用时就测一个极限值 一只小蜜蜂... Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 46893    Accepted Submission(s): 17087 Problem Description 有一只经过训练的蜜蜂只能爬向右侧相邻的蜂房,不能反向爬行.请编程计

HDU - 2044 一只小蜜蜂...

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2044 分析: 从1-2有1种方法,从1-3可以由1-3或1-2-3,总共2种,由1-4可由1-2-3-4或1-3-4或1-2-4总共3种,可以这样想: 想到达4必需到达3或2,然后计算到达3或2的所有路线,加起来就是所有的路线数,f(4)=f(3)+f(2):由此可以想到斐波那契数列 Sample Input 2 1 2 3 6 Sample Output 1 3 *****************

HDU 2044 一只小蜜蜂... HDU 2041 超级楼梯

推公式得出斐波那契数列 #include<stdio.h> __int64 dp[60]; int main(){ int n; #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif int a,b,T; scanf("%d",&T); while(T--){ scanf("%d%d",&a,&b); if(a>b){ pri

HDU 2044 一只小蜜蜂...(递推,Fibonacci)

题意:中文题. 析:首先要想到达第 n 个蜂房,那么必须经 第 n-1 或第 n-2 个蜂房,那么从第 n-1 或第 n-2 个蜂房到达第 n 个,都各自有一条路线, 所以答案就是第 n-1 + 第 n-2 个蜂房,即 ans[i] = ans[i-1] + ans[i-2];注意要用long long 因为超int了. 代码如下: #include <iostream> #include <cstdio> #include <algorithm> #include &

HDU 1160 FatMouse&#39;s Speed 简单DP

FatMouse's Speed Problem Description FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to take the data on a collection of mice and put as large a subset of this data as possible into a sequence so that the

HDU 4960 Another OCD Patient 简单DP

思路: 因为是对称的,所以如果两段是对称的,那么一段的前缀和一定等于另一段的后缀和.根据这个性质,我们可以预处理出这个数列的对称点对.然后最后一个对称段是从哪里开始的,做n^2的DP就可以了. 代码: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath> 6 #include <algori

HDU 5375 Gray code (简单dp)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5375 题面: Gray code Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 626    Accepted Submission(s): 369 Problem Description The reflected binary cod

hdu 2084 数塔(简单dp)

题目 简单dp //简单的dp #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int dp[110][110];//dp[i][j] di i ceng di j ge zui da he int a[110][110]; int main() { int t; scanf("%d",&t); while(t--) { int n;