daimayuan 668. 体育节
作者:互联网
题意:
重排数组,最小化每个位置的前缀极差之和。
思路:
https://zhuanlan.zhihu.com/p/490707329
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + 1 + n);
for(int len = 1; len <= n; len++)
for(int l = 1; l + len - 1 <= n; l++) {
int r = l + len - 1;
f[l][r] = a[r] - a[l] + min(f[l+1][r],f[l][r-1]);
}
cout << f[1][n];
标签:体育节,sort,题意,668,int,daimayuan,len,https 来源: https://www.cnblogs.com/wushansinger/p/16082047.html