# 1049. Mondriaan

Source: Internet
Author: User

Recursive formula F [I] = 3 * f [I-1] + F [I-2]-f [1-3] (I> = 3)

The general formula is f [I] = 2 * (F [0] + F [1] +... + F [n-3]) + 3 * f [N-2] + 2 * f [n-1]

There may be two cases in the range of 1, that is, two squares or one rectangle.

There are three cases in which the range with the length of 2 is removed from the range with the length of 1, that is, the two squares above, the following rectangle, and the upside down and upside down, there are two rectangles, a total of three

If you want to repeat the range with a length greater than or equal to 3 without having a length of 2, you can only overlap two rectangles with one other. Fill the square at the vacancy. There are two kinds

The above generic formula is used to obtain the recursive formula.

# Include <iostream> # include <cstring> using namespace STD; int f [1000001]; int main () {INT cases, O; int N; memset (F, 0, sizeof (f); F [0] = 1; F [1] = 2; F [2] = 7; For (INT I = 3; I <= 1000001; I ++) {f [I] = (3 * f [I-1] + F [I-2]-f [I-3] + 10) % 10; // to prevent negative modulo errors, add 10} CIN> cases; for (O = 1; O <= cases; O ++) {CIN> N; cout <F [N] <Endl;} return 0 ;}

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.