POJ 2506 Tiling

Source: Internet
Author: User

Tiling
Time Limit: 1000 MS Memory Limit: 65536 K
Total Submissions: 6444 Accepted: 3149
Description

In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles?
Here is a sample tiling of a 2x17 rectangle.


Input

Input is a sequence of lines, each line containing an integer number 0 <= n <= 250.
Output www.2cto.com

For each line of input, output one integer number in a separate line giving the number of possible tilings of a 2xn rectangle.
Sample Input

2
8
12
100
200
Sample Output

3
171
2731
845100400152152934331135470251
1071292029505993517027974728227441735014801995855195223534251
Source

The UofA Local 2000.10.14
Research point: recursive formula f (n) = f (n-1) + 2*(n-2 );
Add large numbers
Note: When the input is 0, 1 is output instead of 0.
[Cpp]
# Include <iostream>
# Include <iomanip>
# Include <string. h>
# Include <math. h>
Using namespace std;
Struct num
{
Int s [1000];
Int top;
} A [260];
Int main ()
{
Void deal (int x, int y, int z );
Int I, j, n, m, s, t;
(A [1]. s) [0] = 1; (a [2]. s) [0] = 3;
A [1]. top = 1; a [2]. top = 1;
For (I = 3; I <= 250; I ++)
{
Deal (I-1, I-2, I );
}
While (cin> n)
{
If (n = 0)
{
Cout <1 <endl;
} Else
{
For (I = a [n]. top-1; I> = 0; I --)
{
Cout <(a [n]. s) [I];
}
Cout <endl;
}
}
Return 0;
}
Void deal (int x, int y, int z)
{
Int I, j, l1, l2, max;
Int B [1000], c [1000], d [1000];
L1 = a [x]. top; l2 = a [y]. top;
Memset (B, 0, sizeof (B ));
Memset (c, 0, sizeof (c ));
Memset (d, 0, sizeof (d ));
For (I = 0; I <= l1-1; I ++)
{
B [I] = (a [x]. s) [I];
}
For (I = 0; I <= l2-1; I ++)
{
C [I] = 2 * (a [y]. s) [I]);
}
If (l1> l2)
{
Max = l1;
} Else
{
Max = l2;
}
For (I = 0; I <= max-1; I ++)
{
D [I] = B [I] + c [I];
}
For (I = 0; I <= max-1; I ++)
{
If (d [I]> = 10)
{
D [I + 1] + = d [I]/10;
D [I] = d [I] % 10;
If (I = max-1)
{
Max + = 1;
}
}
}
A [z]. top = max;
For (I = 0; I <= max-1; I ++)
{
(A [z]. s) [I] = d [I];
}
}

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.