oj2568: Statistics Program

Questions asked
in an infinite two-dimensional plane, we make the following assumptions:

1, can only be moved one space;

2, can not go back (assuming your destination is "up", then you can go left, you can right away, you can also go up, but can not go down);

3, through the grid immediately collapse can not walk a second time.

Seeking step number n take a different embodiment (on a two-step process as long as there are not the same, is deemed to be a different program).

Input

First, a given positive integer C, group C expressed test data.

C next row, each row contains an integer n (n <= 20), n represents a leaving step.

Output

Please take the total number of different schemes programmed output n steps;

Each row for output.

The Input the Sample
Raw
2
. 1
2
the Sample the Output
Raw
. 3
. 7
According to subject, a [1] = 3, a [2] = 7, go one step further after each analysis.
There are three directions to go up on the right and left, left to go up two leftward direction, rightward direction right away in two directions
can be introduced a [3] = 17, a [4] = 41. Analyzing conditions may a[i] = a[i - 2] + 2 * a[i - 1];

complete code

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
	int m,n;
	cin>>n;
	int a[30];
	while(n--)
	{
		cin>>m;
	a[1] = 3;
    a[2] = 7;
    for(int i = 3; i <= m; i++)
        a[i] = a[i - 2] + 2 * a[i - 1];
	cout<<a[m]<<endl;
	}
	return 0;
}
Published 38 original articles · won praise 27 · views 3181

Guess you like

Origin blog.csdn.net/qq_45891413/article/details/104979266