Title: give you a 3*n ground, with 1*2 floor tile paved, ask there are several methods.
Analysis: Combinatorial mathematics, dynamic programming. First find the ground to push the relationship.
Only an even number is meaningful, and an odd total area of an odd number must not be true. Once we looked at the two columns as a unit.
If, the last 2 columns constitute a whole part (3 cases, 2*3 3), then there is 3*f (n-2) method;
If, the last 4 columns constitute a whole part (2 cases, upside down implementation), there is 2*f (n-4) method;
...
Therefore, there is a recursive formula: F (N) = 3*f (n-2) + 2 (f (n-4) + f (n-6) + ... );
The sorting simplification can be obtained: f (n)-4*f (n-2) + f (n-4) = 0;
It can be solved by dynamic programming or by a female function.
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace Std;int f[32];int main () {memset (f, 0, sizeof (f)); f[0] = 1;f[2] = 3;for (in t i = 4; I < 31; i + = 2) f[i] = 4*f[i-2]-f[i-4];int n;while (CIN >> n && n >= 0) {cout << f[n] << endl;//female function cout << (int) (((3+sqrt (3.0)) *pow (2+sqrt (3.0), N/2) + (3-SQRT (3.0)) *pow (2-sqrt (3.0), N/2))/6+0.01) << Endl;} return 0;}
UVa 10918-tri Tiling