HDU_2046 Domino shop square (Fibonacci) (return to preliminary)

Domino shop square

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


Problem Description
In a rectangular square of 2 × n, fill the square with a 1 × 2 domino, input n, and output the total number of laying schemes.
For example, when n=3, it is a 2 × 3 square, the laying of dominoes There are three options, as shown below:
 

Input
The input data consists of multiple lines, each line contains an integer n, and the size of the rectangle representing the test instance is 2×n (0<n<=50).
 

Output
For each test instance, output the total number of placement scenarios, one line per instance.
 

Sample Input
 
  
1 3 2
 

Sample Output
 
  
1 3 2

......

Simply recursive thinking, find out the first few groups of numbers, you can deduce the formula

f(n)=f(n-1)+f(n-2)


#include<cstdio>
#include<cstring>
typedef long long ll;
ll a[100];
intmain()
{
	a[0]=1;a[1]=1;a[2]=2;
	for(int i=3;i<100;i++)	a[i]=a[i-1]+a[i-2];
	
	int n;
	while(~scanf("%d",&n))
	{
		printf("%lld\n",a[n]);
		
	}
	return 0;
 }





Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325743248&siteId=291194637