UVa 10918-tri Tiling

Source: Internet
Author: User

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

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.