[HDU] [2044] A Little Bee...

Problem Description

Loading...

Problem Analysis

Another recurrence approach
Writing it out reveals it’s
the Fibonacci sequence

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include<stdio.h>
#include<string.h>
long long a[55];
int main() {
	memset(a,0,sizeof(a));
	a[1]=1;
	for(int i=1; i<51; i++) {
		a[i+1]+=a[i];
		a[i+2]+=a[i];
	}
	int T;
	scanf("%d",&T);
	while(T--) {
		int n,m;
		scanf("%d %d",&n,&m);
		printf("%lld\n",a[m-n+1]);
	}
	return 0;
}

Problem link: HDU [2044] A Little Bee…

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...