Iterable <t> interface and Dynamic Planning

Source: Internet
Author: User
1 iterable <t> Interface

Objects that implement this interface are allowed to be the targets of the "foreach" statement.

From the code point of view, iterable only wraps an iterator <t> iterator (); but after packaging, the iterator becomes iteratable.

After 1.5, foreach and collections all implement the iterable <t> interface. If iterator is implemented, the traversal of list will be list. next (), it is reasonable to maintain a position pointer inside the list and put the pointer in the abstract iterator.

2. Dynamic Planning

The basic idea of dynamic planning is to divide the problem to be solved into several subproblems and solve them in sequence. The solution of the previous subproblem provides useful information for the solution of the latter subproblem.

The basic idea of the dynamic planning algorithm and the divide and conquer method is similar. The difference is that the problems solved by the dynamic planning can be divided into overlapping subproblems, while the rule of divide and conquer can be divided into independent subproblems. That is, dynamic planning is vertical decomposition, while the Division and control method is horizontal decomposition.

The approach of the dynamic planning algorithm is opposite to that of the general recursive algorithm: Generally, the recursive calculation method is top-down, while the dynamic planning method is bottom-up. The advantage is that problems that have been solved are saved to avoid repeated computation.

Because dynamic planning is vertical splitting, its conditions are strict and must meet the following requirements:

  • No aftereffect. The future has nothing to do with the past. The solution of the parent stage is not affected by the Child stage. From the status chart, the state chart is constrained by a non-loop state chart. The physical meaning of this condition is that the original problem can be vertically divided into multiple subproblems (stages ).
  • Optimization Principle. The sub-policies of an optimization strategy are always optimal. If this condition is met, the problem can be divided into several possible solutions and the subproblems corresponding to each solution. The physical meaning of this condition lies in the subproblem of vertical decomposition. The independently obtained solution is the optimal solution. (It seems to be reversed. It is to be corrected)

Dynamic Programming.

 

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.