Hdoj 2563 Statistical problems (recursion)

Source: Internet
Author: User
Statistical issues Time limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 6413 Accepted Submission (s): 3787


Problem Description in an infinitely large two-dimensional plane, we make the following assumptions:
1, can only move one grid at a time;
2, can not go backwards (assuming your destination is "up", then you can go to the left, you can go to the right, you can go up, but not down);
3, through the lattice immediately collapsed can not go again the second time;

The number of different schemes for N-Steps (2 methods are considered different if one step is not the same).

Input first gives a positive integer c, which indicates that there is a C set of test data
In the next line of C, each line contains an integer n (n<=20), which indicates that you want to walk n steps.

Output Please program the total number of different programs to go n steps;
One row for each set of outputs.

Sample Input
2 1 2
Sample Output
3 7 in the beginning unexpectedly want to use DFS to beg, finally found stupid home, Khan = =. Push a Table AC code:
#include <stdio.h>
int num[25];
void block ()
{
	num[0]=1;
	num[1]=3;
	for (int i=2;i<=20;i++)
	{
		num[i]=num[i-1]*2+num[i-2];
	}
}
int main ()
{
	block ();
	int n,t;
	scanf ("%d", &t);
	while (t--)
	{
		scanf ("%d", &n);
		printf ("%d\n", Num[n]);
	}
	return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.