HDU-2046 bone plate shop square [recurrence]

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2046

Solution:

This aspect of recursion is closely related to mathematics, so I will take a look at the relevant knowledge. This question is a simple question and can be thought out.

Because can only put 1X2 specifications of the bone card, then, the n size of the grid can only be obtained from N-1 and N-2, n-1 when we add a 2x1 grid, vertical put, there can be f (n-1) Put method, N-2 when we can increase 2 × 2 lattice, 2 are placed horizontally, there can be f (n-2) method.

The idea of this question is the same as that of super step. N state can be obtained from n-1 state and N-2 state, so it can be solved by recursion. (DP thinking is also acceptable)

In addition, when n is relatively large, it may exceed int, so you can test it. It is impossible to use a large number.

CodeAs follows:

# Include <iostream >#include <cstdio> using namespace STD ;__ int64 DP [55] = {0, 1, 2, 3}; void fun () {for (INT I = 4; I <= 50; ++ I) DP [I] = DP [I-1] + dp [I-2];} int main () {int N; fun (); While (scanf ("% d", & N )! = EOF) printf ("% i64d \ n", DP [N]); Return 0 ;}

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.