$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 ;
}
随机推荐
- ubuntu14.04 fcitx安装
先卸载ibus sudo apt-get remove ibus (也可尝试不卸载ibus,直接安装fcitx) 添加源 sudo add-apt-repository ppa:fcitx-team/ ...
- Python面向对象之面向对象封装案例
面向对象封装案例 封装 封装是面型对象编程的一大特点 面向对象编程的第一步--将属性和方法封装到一个抽象的类中: 外界使用类创建对象,然后让对象调用方法: 对象方法的细节都被封装在类的内部. 一个对象 ...
- pandas处理各类表格数据
经常遇到Python读取excel和csv还有其他各种文件的内容.json还有web端的读取还是比较简单,但是excel和csv的读写是很麻烦.这里记录了pandas库提供的方法来实现文本内容和Dat ...
- PAT 1146 Topological Order
This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...
- CodeForces 1000F One Occurrence
You are given an array $a$ consisting of $n$ integers, and $q$ queries to it. $i$-th query is denote ...
- 在JQuery中$(document.body)和这个$("body") 这两的区别在哪里?
两种写法代表的是同一个对象 $("body") 是一个选择器,jQuery 会从 DOM 顶端开始搜索,直到找到标签为 body 的元素. 而 $(document.body) 中 ...
- java 源码分析1 -String
1. String的本质是一个 char数组,实现了CharSequence 接口, /** The value is used for character storage. */ private f ...
- python基础学习之02 序列
#encoding=utf-8 import math a=[1,23,4,5,6] print a a[1:1]=[2,3,5] print a a a[1]='a' print a a[1]={1 ...
- android (13) Fragment使用下
一.Fragment使用: 要在你的activity中管理Fragment,须要使用FragmentManager,能够通过getFragmentManager(),这里注意要是在v4包要用getSu ...
- 基于FPGA的简易数字时钟
基于FPGA的可显示数字时钟,设计思路为自底向上,包含三个子模块:时钟模块,进制转换模块.led显示模块.所用到的FPGA晶振频率为50Mhz,首先利用它得到1hz的时钟然后然后得到时钟模块.把时钟模 ...