Hdu 3045

来源:互联网 发布:淘宝禁卖 中药材 编辑:程序博客网 时间:2024/06/16 20:48

It’s summer vocation now. After tedious milking, cows are tired and wish to take a holiday. So Farmer Carolina considers having a picnic beside the river. But there is a problem, not all the cows consider it’s a good idea! Some cows like to swim in West Lake, some prefer to have a dinner in Shangri-la ,and others want to do something different. But in order to manage expediently, Carolina coerces all cows to have a picnic!
Farmer Carolina takes her N (1

题意:

有n个奶牛分别有对应的兴趣值,现在对奶牛分组,每组成员不少于t,在每组中所有的成员兴趣值要减少到一致,问总共最少需要减少的兴趣值是多少。

题解:


先对n个数进行排序,则可以分析出分组成员一定是连续的
dp[i]表示前i个数得到的最少值
则:从j~i作为一组
dp[i]=dp[j-1]+sum[i]-sum[j-1]-(i-j+1)*s[j];//sum[i]表示前i个数的和
=>dp[i]=dp[j-1]+sum[i]-sum[j-1]+(j-1)*s[j]-i*s[j];
由于有i*s[j]这一项,所以无法直接在扫描数组的过程中用单调队列维护:
dp[j-1]-sum[j-1]+(j-1)*s[j]-i*s[j]的最小值。
考虑用斜率dp!
假定k

2 0