Test instructions
There are two boxes of uranium (U) and lead (L), which are now lined with n boxes (two boxes are enough) and require at least 3 uranium to be put together to ask how many methods of emissions are available.
Analysis:
n boxes in a row, a total of 2n in the scheme, which conforms to the requirements of the F (N) species.
F (n) can be introduced in the following two cases:
- The first n-1 box is placed to meet the requirements, the nth box can be placed u can also be placed L, a total of 2xf (n-1) in the scheme
- The first n-1 box does not meet the requirements, to make the first n boxes meet the requirements, the first n-2, n-1, n boxes must be U. And because of the previous hypothesis, the first n-3 box must be L (otherwise the first n-1 box satisfies the requirements). So we make sure the last four boxes are luuu, the front n-4 box as long as not contain three consecutive U. Total 2n-4-f (n-4) in the scheme
Synthetic, f (n) = 2XF (n-1) + 2n-4-f (n-4)
1#include <cstdio>2typedefLong LongLL;3 4LL f[ *];5 6 intMain ()7 {8 intN;9f[3] =1, f[4] =3;Ten for(inti =5; I <= -; ++i) F[i] =2*f[i-1]-f[i-4] + (1<< (I-4)); One while(SCANF ("%d", &n) = =1&&N) Aprintf"%lld\n", F[n]); - - return 0; the}code June
UVa 580 (Recursive) Critical Mass