| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 526 人关注过本帖
标题:一道简单题求思路
取消只看楼主 加入收藏
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
快速回复:一道简单题求思路
数据加载中...
 
   



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

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