标题:一道简单题求思路
取消只看楼主
chuangketie1
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-10-18
结帖率:0
已结贴  问题点数:20 回复次数:0 
一道简单题求思路
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
我只有暴力直接算的思路,因此总是超时。不知道各位大神有什么想法,这题可以用动态规划解吗?
搜索更多相关主题的帖子: positive sequence number single 暴力 
2013-10-18 17:07



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-422131-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.446065 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved