Question:
The length (<= 3000) of N wooden sticks is given. Each wooden stick can be cut off by the length of [1, m] to get a new wooden stick. The maximum length that cannot be combined. If any length can be combined or the maximum value has no upper limit for output-1. (1 <n <100, 0 <= m <3000 ),
Problem solving process:
1. This is the case of usaco 4.1, but the data has been enhanced. At that time, I used it as a backpack, and then determined a large range (60000 was selected at that time) to determine whether the length in this range can be combined, if yes, output-1. otherwise, the maximum output length cannot be combined .. The same is true for most of nocow, but why is this possible? It seems that no one has provided a good proof (at least I didn't understand it, and I felt wrong)
2. Let's look at this question again. The length range of each wooden stick of this question has changed to 3000 (only 10 for the wheat fragrant ox block), and it is difficult to determine a range .. After reading the question solution (at the bottom of the vijos question solution column), we will find great gains. The following describes the practices.
First of all, there are still a lot of candidates to do it within a certain range, which is a bit of luck. The following method should be more rigorous:
1. First pre-process all the original wooden stick lengths that can be produced, and find the smallest one, which is recorded as p. If p = 1, you don't need to do it anymore. Directly output-1.
2. all integers are divided into P classes by mod P values (mod p =, 4... p-1), as set q0, Q1, Q2...QP-1 if the set Qi has a length Len can be combined, then all the numbers in the set than Len can be combined. because it is mod P, Len can continually add P to combine numbers larger than it and in the same set as it. Based on this nature, we can find the graph theory model.
3. We abstract the points of the P-1, which respectively represent the smallest number d [I] that can be combined in the Set Qi. Based on the length of the original wooden stick, edge can be connected between these points, indicating that a number in Qj can be obtained from a number in Qi plus X.
Then, the spfa algorithm can be used to obtain the minimum number of Qi in the set. A small optimization can reduce the number of edges, that is, if the weight of multiple edges is equal to mod P, you only need to add one of them (according to the same theorem ).
4. How can I obtain the answer based on the value of d [I? Or use the property "if there is a length Len in the Set Qi that can be combined, then all the numbers in the set that are larger than Len can be combined. Check every d [I] in sequence. If D [I]> I, the maximum number that cannot be combined in the Set Qi is d [I]-P. Check all the values of d [I.
Conclusion: The graph theory + number topic is very flexible, and the transformation of graph theory models is very clever.
Farm fencing (vijos 1054)