optimized (multi-stitch version) dancing link
Here, I list the pseudocode of this algorithm, I didn’t implement it since it wasn’t critical for my journal…
But If you are required to implement a DL with dynamic working stitches. Hope this piece of code helps you. :)
The basic requirement of “dynamic” is:
Given a working stitch k in each polygon, the alg construct corresponding coloring rows in the dancing links.
Note that we need exactly k working stitches instead of # <= k (Since the optimality of DL is constraint by the row order, for example, if one polygon $p$ contains three stitches, then the rows indicating $p$ at beginning should be the coloring solution without working stitch, following is the # of exactly one stitch… and so on
1 | def insert_exactly_k_stitches(k): |
for 循环中新建structure
如果直接用 Structure a = Structure(args), 这个loop里面的a都是一个address
解决方法:new
1 | liwei* a = new liwei(i); |