The algorithm is what I can't remember, but I do it my means. Two

Source: Internet
Author: User

Yesterday did an algorithm problem to everyone to share the next my solution, there is a constructive opinion, there is support and see smattering. I think of what you can do to optimize the place, paste the optimization program. The original question and the solution process are http://www.cnblogs.com/xianyudotnet/p/5887304.html here .

Main points of the topic:

Given a 0,1 matrix, the matrix of 1 is the path, left and right to move the consumption of physical energy 1, the upper shift consumes 3, the lower shift is not consumed. The minimum consumption path for the upper-left corner to the upper-right corner given a physical value. A 8*8 matrix was established for the convenience of testing.

This is the path.

The result of the original method:

The idea of solving the problem in the previous article is: the movement of the recursive simulation path, the discovery of a given physical value of all the movable path, and then select the minimum physical energy consumption path.

I changed the code, controlled the input and output, ran the matrix for the comparison test, the result is this.

  

Optimization scenarios:

1. First solve the loop path problem. The original method as long as the physical energy is not exhausted, the circulation path is still circulating until the physical consumption is complete, which is quite unscientific. Then after moving to check whether the current coordinates in the road strength, in the description loop, directly discard this path.

2. The second is the problem of physical value. If a feasible path has been found and the physical energy p is consumed, then all subsequent paths that consume more energy than P will be discarded.

Some students mentioned that the energy value is the optimal solution from increasing the cycle of minimum physical value to recursion until the path is found. Of course, but the solution is very good, the efficiency is not as fixed as the original method of physical value. Later, I mentioned that the method of using division to fix the physical strength, and later found that I was naive. Because once recursive if find solution that is optimal, did not find and adjust the physical range, and then recursive search, repeated calculation too much, but also for the original method of the situation. The new method The second optimization has been the dynamic adjustment of physical limits, the external adjustment of the physical range is meaningless and less useful. So the optimized efficiency is like this.

Optimization results:

Code:

  

  

Many people say that with this algorithm, that algorithm, a lot of nouns ... I looked at those formulas and really had a headache. I have the time and the energy must strive to improve oneself study advanced posture level. My wild algorithm is like this, after the optimization of the sense of efficiency is also reasonable.

Want to test still GitHub on a pickup, two versions of the Code are: Https://github.com/631320085/Algorithm

This question I think again improve, probably is to use data structure that set, build path model, use on the tall formula minute cock bombing day is right. I'll try hard in the future.

The algorithm is what I can't remember, but I do it my means. Two

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.