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
212
Sample Output
37
Some statistical problems can be directly through a number of steps to find the law, but this is only three steps can make people vomit blood, so still have to analyze the process of change law
F[n] for the nth step of the scheme, A[n] for the upward walk of the scheme, B[n] to the left and right of the scheme
Easy to get f[n]=a[n]+b[n];
And the previous step no matter where to go, this step can go upward, so a[n]=a[n-1]+b[n-1]=f[n-1];
If the previous step left, then this step in addition to the left to go, so it was b[n]=2* (A[n-1]+b[n-1]), but less about a situation, to subtract b[n-1], so b[n]=2*a[n-1]+b[n-1];
Bring the above two equations into the f[n]
f[n]=2* (a[n-1]+b[n-1]) +a[n-1]=2*f[n-1]+f[n-2];
#include <iostream> #include <cstring> #include <algorithm> #include <cstdio>using namespace Std;int Main () { int n,i,j,m,a[30]; scanf ("%d", &n); while (n--) { a[0]=3; a[1]=7; scanf ("%d", &m); for (I=2;i<m;++i) a[i]=2*a[i-1]+a[i-2]; printf ("%d\n", A[m-1]); } return 0;}
Some projects--statistical issues