-
Web Links.
Look at the explanation at this meeting, and you will understand.
-
Regarding this kind of recursive exhaustive **, I think:
1) After semantically understanding what the whole does, it will be much easier to look at it. Otherwise, you'll be overwhelmed by the endless stacks of entries and exits.
2) There is no need to go to the next level of recursion, but to skip recursion with 1) understood semantics**. If it can be explained logically, it means that this ** is basically correct.
3) Finally, take a second look, as long as you make sure that every branch has gone to it, you can consider the algorithm correct.
Use the above ideas to read DFS.
1) Get a general understanding of the basic functions of DFS, and (starting with the first chest) find a working card for the first chest. That is, DFS(1) is to find available cards for the first chest, DFS(2) is to find available cards for the second chest, and DFS(STEP) is to find available cards for the first chest. Remember not to enter recursion, otherwise it will be endless, the computer will not be dizzy, you will be dizzy first.
2) It's now possible to peruse it a little. The i in the for cycle enumerates all the cards to determine if they are available for the next chest. We can imagine that before that, the cards had been found in chests from 1st to 1st step-1.
After finding the cards for the first card, call def (step+1) to continue looking for cards for the next chest. Remember not to read the details of def(step+1)! Finally, book[i]=0 means that the available card is released for use in subsequent chests.
Logically it is already clear. For example, in the first chest, the for cycle can be played 9 times, and each time you find 1 available card. For the 2nd chest, the for loop can be done 8 times because one has already been divided.
And so on, all chests are dealt with by def(step+1), and there is also a chance to get any card. It shows that the exhaustive action is complete and the algorithm is correct.
Again, def(step+1) means that the first chest has found an available card and can try the next one. The for cycle is to ensure that the first chest can find all the currently available cards, and then use def (step+1) to try the next chest. If you learn permutations and combinations a little better, you will understand that this is a 9!
implementation.
-
After typing for a long time, I still deleted it all.
Give a suggestion: refer to the instructions in the book, and understand the example step by step (**, enter the function to step through the debugging).
-
You should shoot the problem directly, which is much more useful than if you were to film the problem-solving process.
Night, quietly. The night is expected to be endless, and it will be dark all around. The whole street is only dim street lamps and few pedestrians. >>>More
The poem "Huanxi Sha" was written by Su Shi at the age of 43 when he was too punctual in Xuzhou. In the spring of that year, there was a severe drought in Xuzhou, and Su Shi, as a magistrate, led the people to Shitan, 20 miles east of the city, to ask for rain. After getting the rain, he went to Shitan with the people to thank the rain. >>>More
1. If the angles of two phases (corresponding) are equal, then their complementary angles are equal. >>>More
The willows flutter together with the wind. The flying branches and leaves, scattered and orderly, not barren, not decadent. >>>More
Find it on the net! As soon as I looked for it, there were a lot of them.