$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 ;
}
随机推荐
- Linux命令学习(2): scp和rsync基本用法与断点续传
版权声明:本文为博主原创文章,未经允许不得转载. 引子 在平常的工作中,我经常需要在远程服务器和本地之间传输文件. 以前我都使用scp命令,直到今天因为网络中断,scp出现了stalled. 因为上传 ...
- 设置Python解析器
如果同时安装了多个Python,如 Python2.7 和 Python3.7 .如果某些特殊原因(比如有些框架只能在Python2.7中使用),需要修改程序在 Python2.7 下运行,即可设置P ...
- vuex----mutation和action的基本使用
我们要实现的很简单,就是点击+1的count加一,点击-1的时候count-1 一.mutation 在vue 中,只有mutation 才能改变state. mutation 类似事件,每一个mu ...
- 微信小程序-template模板
============================= 构建template模板 ============================= 1.分析得出共为 ...
- Leetcode 79.单词搜索
单词搜索 给定一个二维网格和一个单词,找出该单词是否存在于网格中. 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中"相邻"单元格是那些水平相邻或垂直相邻的单元格.同一个单 ...
- Python学习笔记 (1)Hello World(环境搭建+输出Hello World!)
随想 高考发挥失常.科三遇火车发挥失常,各种不顺……突然发现假期都快没了,才想起高考前想象的这个假期要做的一堆事,现在来多完成一件吧. 这几篇博客仅只是我的学习笔记,凑合看吧.我这个python小白看 ...
- 1827 tarjan+缩点
#include<stdio.h> #include<stack> #include<iostream> #include<string.h> #inc ...
- 网上的仿QQ验证码,详细使用方法
struts2的配置 和代码 1.生成图片流 类名:VerifyCodeUtils /** * 生成图片流 * @author Administrator * */ import java.awt.C ...
- Eclipse安装Properties插件来编辑中文
一.在线安装 输入这个地址:http://propedit.osdn.jp/eclipse/updates/ 二.离线安装 在官网上下载最新版本:https://zh.osdn.net/project ...
- HDU 4849 Wow! Such City!陕西邀请赛C(最短路)
HDU 4849 Wow! Such City! 题目链接 题意:依照题目中的公式构造出临接矩阵后.求出1到2 - n最短路%M的最小值 思路:就依据题目中方法构造矩阵,然后写一个dijkstra,利 ...