ZJU2037 Parliament-integer split with the maximum Product

Source: Internet
Author: User

Description:

Given an integer n (<= 1000), a division scheme is proposed to make each item different with the maximum product.

Analysis:

As soon as you see the question, intuition tells me that this question must beDynamic Planning. So I have been heading for this great goal ......

I first thought aboutDP of n ^ 4, Think it will time out;

ChangedDP of n ^ 3, There should be little hope;

Continue to change ...... The audience finally gotDP of n ^ 2Come out! Wow, haha ......

Because after WA is exceeded the int range once, it is changed to double and the final result is 0.16s ~ :)

Then I searched Baidu to find that I couldStructure, Time complexity O (n)...> _ <| Cracking ing

My spam DP is not mentioned. Let's talk about a constructor I have seen:

Obtain2. sum of the largest continuous natural number sequence at the beginningTo make the sum valueNo more than nAnd then discuss the situation as follows:

Set the maximum sequence to 2, 3 ,...... ,W, Then:

1.If the remaining value (n-sum) is w, The final output sequence is: 3, 4 ,...... , W, w + 2, that is, add 1 to each item of the original largest sequence, and then add the remaining 1 to the last item.

2.If the remaining value (n-sum) is less than wFrom the sequence entry I, add 1 to each item in sequence from large to small until the remaining value is used up.

Reference: http://twins-sbc.spaces.live.com/blog/cns! E464fe74dab33208! 569. entry

 

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.