Who can give me some ideas

There is no good way to only the violence algorithm, for help. The original title.
To give you a number of columns, define f (I) is I and before the minimum number |ai-aj| (i> J) for F(1)+f(2)+....+f(n)
There is a number sequence A1,A2,...,An. Let f(i)=min{|Aj-Ai| ,j<i}. You only need to compute f(1)+f(2)+...+f(n).
Input
The first line is an integer c which shows the number of cases. For each case there is a single line. The first number is n and the next n positive integer is A1 to An. (n<10000, Ai<100000)
Output
For each case print the answer at a single line.
Sample Input
2
3 1 2 3
4 2 3 1 4
Sample Output
2
3
A new idea for······

Started by Brian at November 18, 2016 - 6:12 PM

I guess it is using dynamic programming. . .

Posted by Lynn at November 24, 2016 - 6:28 PM

With a number of J records the decimal position.
Is j = 0;
f = 0;
Calculation of S + = ABS from I = 1 (a[i]-a[j]); if a[i]<a[j] j = i;
The calculation to the end of n
But n need to read it.

Is a cycle.
An absolute value, and the sum,
A comparative and record.
Because the case is a dual cycle.

Posted by Aldrich at December 02, 2016 - 6:33 PM

The minimum requirement is |a[i]-a[j]|······

Posted by Brian at December 12, 2016 - 6:39 PM

2, know the equation of state and the sub problem is what

Posted by Brian at December 16, 2016 - 6:48 PM