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