Blog (http://blog.csdn.net/livelylittlefish
) Post the notes prepared by the author (a bo) on the relevant research and study content. You are welcome to correct them!
Content
0.
Problem
1.
Some methods
2.
Mathematical Analysis
3.
Can I Program Computing?
4.
An Improved Method
5.
Method for further improvement
6.
Can we directly calculate and find all the correct solutions?
7.
A simpler method
8.
Automatic compilation and running of all codes
9.
Problem Expansion
10.
Experience
11.
Summary
Reference
Appendix
1
: Code for mathematical Decomposition
Weight1.c
Appendix
2
: Mathematical decomposition Program
Weight1
Running result
Appendix
3
: Code for tree structure Decomposition
Weight2.c
Appendix
4
: Code of the improved method
Weight3.1.c/3.2.c/3.3.c
Appendix
5
: Code of the improved method
Weight3.1.c/3.2.c/3.3.c
Output result
Appendix
6
: Directly calculate the correct decomposition code
Weight4.c
Appendix
7
: Code for a simpler method
Weight5.1.c/5.2.c/5.3.c
11.
Summary
This article first gives various answers
And analyzes the decomposition method of the problem from the mathematical point of view.
(
The
2
Section
)
And
3
Section
A pure mathematical computing program is provided.
Weight1.c
This method uses several one-dimensional, two-dimensional, and three-dimensional arrays to save the decomposition results. This method has many definitions of arrays. If other conditions are added, such as one more weighing, it is difficult to expand.
The
4
Section
A tree structure is used to store the weighing process.
(
Decomposition result
)
. Compared
3
Section
Mathematical method. This method does not require so many array definitions,
Its
The data structure is unified, simple, and saves a lot of space. However, this method also has disadvantages. For example, the final correct solution is only
5
, But the method is the same
3
Section
The same mathematical method, calculates all result-based solutions
37
Is also a waste.
The
5
Section
Yes
4
Section tree structure saves the improved version of the weighing process method, that is
3
The secondary decomposition result is used to determine whether a node is created only when the weighing process meets the target.
2
Layer and
3
Layer node. In this way, there are no nodes with decomposition results
(
Including
2
Layer and
3
Layer Nodes
)
Will not be created,
Its
All leaf nodes are correct decomposition results. The problem is more intuitive and saves space
.
The
6
Section
Calculate
3
Starting from the next weighing, that is,
2
Secondary Decomposition
(
Weighing
)
Then,
3
Obtain the next weighing solution and determine the number
3
Whether the weight used for secondary weighing is in the weight combination. If the weighing process is correct, give up and continue to judge.
This method directly calculates
3
Times of decomposition to better understand and further simplify the decomposition process.
The
7
Section
From the perspective of not saving every weighing result, this problem is analyzed using the Backtracking Method and converted into common programming. Compared with the methods in the previous sections, the method in this section is simpler.
3
All correct solutions can be obtained through nested layer calls without the need to save each weighing result. The logic is simple, intuitive, and easy to implement,
Should be the preferred method
.
The
8
Section
The methods for automatically compiling, running, and saving the running results of all examples in this article are discussed in terms of program compilation and running.
The
9
Section
The extension of this problem is briefly discussed. The
10
Section
This article briefly discusses the author's experience in writing this article. The
11
Section
The last section summarizes the full text and the methods discussed in this article.
Reference
<
Computer Algorithm Design and Analysis
>
Weight weighing Problems
(
Abo
)
Write
Makefile
(
Abo
)
Control
Makefile
(
Li Yun
)
Write with me
Makefile
(
Chen Hao
)
Classic algorithm (
1
)--
8
Queen Problem Solving (backtracking)
(
Abo
)
Previous section
Thinking questions
, Tree Structure
, Weight to Salt