Translation How to find a solution (finding the answer to the question from the top coder website)

Source: Internet
Author: User

Original link: https://www.topcoder.com/community/data-science/data-science-tutorials/how-to-find-a-solution/

Personal feeling, this article is very good, from a relatively high height, relatively systematic summary of some classical algorithm problems of the classical ideas. Translation is to facilitate their understanding and learning, but also hope to help the needy friends.

The full text is very long, I will part of the slow moving.

    1. Dynamic programming problem of dynamical programming
    2. Cond

Dynamic programming (dynamically planned)

Quite a number of problems are solved with this algorithm technique, so it is valuable to know how to identify such problems. However, this requires that we have considerable programming experience in dynamic programming.

Typically, a dynamic programming problem has several major integer variables (such as N). These variables are usually neither too small nor too large. This is because the complexity of the dynamic programming problem is usually n^2, or n^3, neither too big nor too small n will be more appropriate. It is important to note that if n is small, (for the problem on top coder, N is very small refers to n drizzle 30), then many of these may not be a dynamic planning problem.

In addition to this, there are some States (states) and some corresponding rules (rule) in the first class of the dynamic planning problem. With these rules, a smaller state can reach a larger state. Moreover, a larger state should be dependent on a smaller state only. So what is the so-called state? The state is actually some particular situation or situation. Read this article if you want to learn more about dynamic planning issues.

Next, let's analyze a classic dynamic programming problem together.

Give you n coins, and their currency (V1,v2,.. VN). Tell you again a sum of S. Please figure out the minimum number of coins that can be combined to sum S. (You can use any number of coins for any one currency). If there is no one combination that can be the sum of S, return "impossible". Assume N <= 100 and S <= 1000.

Message from the question:

* The problem gives two main integer variables (s and N), and both are of the right size. (That is, N * S is within a time complexity range that can be resolved).

* Status (State) can be defined as: In order to be able to combine the sum of a certain value, the minimum number of coins required.

* Larger state I, only dependent on smaller states state J (J < i). Here I, J, respectively, represent a sum that needs to be combined. State I means the minimum number of coins needed to make up the sum of I.

* If you add a coin to a particular state, you can get a larger sum, that is, from a smaller state to a larger state.

With this analysis, the topic has the basic elements of all dynamic planning. Next, let's look at a slightly more difficult dynamic planning problem.

ZigZag-2003 TCCC Semifinals 3:

A sequence of numbers is called a zigzag sequence (a sawtooth sequence, if a sequence of two consecutive numbers of differences consists of a new sequence of strict positive and negative numbers alternately appearing. The first difference, if one exists, can be a positive number or negative. A sequence of any length less than 2 is considered to be a sawtooth sequence. Give you a set of numbers to find the oldest sequence in which the sawtooth sequence is. (a subsequence is a sequence that removes 0 or more elements from the original sequence and retains the relative order of the remaining elements in the original sequence). Suppose the given sequence length is less than 50.

Tips from the topic:

* The number of n is given (n is 50 or less).

* Status State (I, D) can be defined in this way: the length of the longest sawtooth subsequence ending with the first number in the sequence, and if the second-to-last number in the subsequence is less than the final number, d = 0, and vice versa, D = 1.

* Status state I, only dependent on States J (J < i)

* Add a number to the end of the subsequence to reach a larger state.

Above, we can see that this problem also has all the basic elements of dynamic planning problems.

The hardest part of a dynamic programming problem is finding or defining a state, and once that is done, the rest of the work is the answer to the organization's question, which is beyond the scope of this article to discuss.

Translation How to find a solution (finding the answer to the question from the top coder website)

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.