HDU 1143 Tri Tiling recursion problem

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.