$P5017 摆渡车$
毒瘤\(DP\)
#ifdef Dubug
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long LL ;
inline LL In() { LL res(0),f(1); register char c ;
while(isspace(c=getchar())) ; c == '-'? f = -1 , c = getchar() : 0 ;
while(res = (res << 1) + (res << 3) + (c & 15) , isdigit(c=getchar())) ;
return res * f ;
}
int n , m ;
const int N = 500 + 5 ;
const int M = 100 + 5 ;
int t[N] , res[N] ;
int dp[N][M] ;
signed main() {
memset(dp,0x7f,sizeof(dp)) ;
n = In() , m = In() ;
for(register int i=1;i<=n;i++) t[i] = In() ;
sort(t+1 , t+n+1) ;
for(register int i=1;i<=n;i++) res[i] = res[i-1] + t[i] ;
t[0] = -0x7f7f7f7f , dp[0][0] = 0 ;
for(register int i=0;i<=n;i++) {
int Min = min(t[i+1]-t[i] , m-1) ;
for(register int j=0;j<=Min;j++)
if(dp[i][j] != 0x7f7f7f7f)
for(register int k=1;k+i<=n;k++) {
int Max = max(t[i]+j+m-t[i+k] , 0) ;
dp[i+k][Max] = min(dp[i+k][Max] , dp[i][j] + (Max + t[i+k]) * k-(res[i + k] - res[i])) ;
}
}
int ans = 0x7f7f7f7f ;
for(register int i=0;i<m;i++) ans = min(dp[n][i] , ans) ;
cout << ans << endl ;
return 0 ;
}
随机推荐
- 每日命令:(10)cat
cat命令的用途是连接文件或标准输入并打印.这个命令常用来显示文件内容,或者将几个文件连接起来显示,或者从标准输入读取内容并显示,它常与重定向符号配合使用. 1.命令格式: cat [选项] [文件] ...
- Linux:iscsi存储服务器配置
服务器添加4块硬盘 mdadm -Cv /dev/md0 -n 3 -l 5 -x 1 /dev/sdb /dev/sdc /dev/sdd /dev/sde 记下UUID值 mdadm -D /de ...
- linux下Mongodb集群搭建:分片+副本集
三台服务器 192.168.1.40/41/42 安装包 mongodb-linux-x86_64-amazon2-4.0.1.tgz 服务规划 服务器40 服务器41 服务器42 mongo ...
- this与const
在普通非const成员函数中,this是const指针,而在const成员函数中,this是const对象的const指针. class Foo { Foo& get_self1(void) ...
- 恶补---bell数
定义 bell数即一个集合划分的数目 示例 前几项的bell数列为 1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147, 115975 ,... 求值方法 1.bell ...
- Spring 工厂方法创建Bean 学习(三)
1, 静态工厂方法创建Bean 调用静态工厂方法创建 Bean是将对象创建的过程封装到静态方法中. 当客户端需要对象时, 只需要简单地调用静态方法, 而不同关心创建对象的细节. 要声明通过静态方法创建 ...
- 【Codeforces 598D】Igor In the Museum
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 同一个联通块里面答案都一样. 把每个联通块的答案都算出来 然后赋值就好 [代码] #include <bits/stdc++.h> ...
- 关于字符串不为空 错误:s!=null
错误:s!=null 正确:StringUtils.isNotBlank(s); public static boolean isBlank(CharSequence cs) { int strLen ...
- [luoguP2863] [USACO06JAN]牛的舞会The Cow Prom(Tarjan)
传送门 有向图,找点数大于1的强连通分量个数 ——代码 #include <stack> #include <cstdio> #include <cstring> ...
- 爬虫——使用ItemLoader维护item
在item的Filed()中设置参数函数,可以用来预处理item字段的数据,另一方面也方便程序代码的管理和重用 item中 from scrapy.loader.processors import M ...