Fills a 3*n rectangle with a 1*2 rectangle, which must not be filled when n is odd,n*3%2==1
The next thing we want to do with this is to start with a simple scenario where recursion is about reducing the size of the problem and solving it by solving the problem. If it's 3*2, there are only 3 possible cases.
So let's consider whether some of the 3*4 rectangles are a combination of these two 3*2 rectangles, and of course include a special case where the stitching method is shown
Put 4, 6, 8 .... As a whole piece, there are two cases (positive, inverted)
Then we can divide the various cases into the following two major categories
A rectangle formed by itself (i.e. not divisible)
The case can be divided, namely 2*f (n-2i) (2i>2)/3*f (n-2i) (at this time 2i==2)
The code is as follows:
1#include <iostream>2#include <cstdio>3 using namespacestd;4 intTillintN)5 {6 ints,i;7 if(n!=2)8 {9s=2;Ten } One Else A return 3; - for(i=2;i<N;) - { the if(i==2) -s=s+3*till (ni); - Else -s=s+2*till (ni); +i=i+2; - } + returns; A } at intMain () - { - intN; - while(cin>>N) - { - if(n==-1) in Break; - if(n%2==1) tocout<<0<<Endl; + Else if(n==0) -cout<<1<<Endl; the Else *Cout<<till (n) <<Endl; $ }Panax Notoginseng return 0; -}
HDU 1143 Tri Tiling recursion problem