My idea is to use no. 1 steel bar respectively at the back of the 49 steel bar, ask us a, 12 - a> judgement;=0 and compare the size of the 49 a, taking the minimum, the minimum value of a corresponding reinforcement is the best match with 1, then find and 2 the best match of reinforcing steel bar, and so on
Didn't know that I the idea is not correct, or to have a great god has a better idea, because I have only learned a few months of JAVA, a great god can give the code, just as a small interesting topic to the great god,,,
CodePudding user response:
If two addition, the overall train of thought should be the first to all steel bar length, sorting, and then the shortest and longest addition, if more than 12, carry on and second longest shortest addition, by analogy, when less than 12, long number is the minimum number of matches, then a second shorter and smaller than the front short matching to the long steel 筯 addition, reason, can match with the shortest second match not more, in short, for example: 2,3,3,4,5,5,6,10,11,2 + 11, do not match, continue to 2 + 10, then 3 + 6, 11 have can be ignored