Question: Question 5. Write a Java program and find the answer: Some nails are hammered on a straight plank. Any two nails can be joined by
Question 5. Write a Java program and find the answer:
Some nails are hammered on a straight plank. Any two nails can be joined by a thread. Connect some pairs of nails with a thread, so that to each nail will be tied with at least one thread, and the total length of all threads will be minimal.
The first line contains the number of nails n (1 n 100). The next line contains n numbers - the coordinates of all the nails (non-negative integers not exceeding 10000). Print the minimum total length of all threads. Solve the problem for the next input:
15
9731 6194 9485 464 8805 4231 5063 5638 2604 448 84 9631 3034 5153 7526
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
