problem

毒瘤\(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 ;
}

随机推荐

  1. PAT 1135 Is It A Red-Black Tree

    There is a kind of balanced binary search tree named red-black tree in the data structure. It has th ...

  2. [COGS311] Redundant Paths

    ★★☆   输入文件:rpaths.in   输出文件:rpaths.out   简单对比 时间限制:1 s   内存限制:128 MB Description In order to get fro ...

  3. windows开启3306端口并用可视化工具访问远程mysql(授权访问)

    开启 MySQL 的远程登陆帐号有两大步: 1.确定服务器上的防火墙没有阻止 3306 端口. MySQL 默认的端口是 3306 ,需要确定防火墙没有阻止 3306 端口,否则远程是无法通过 330 ...

  4. tomcat管理员password设置

    打开tomcat安装文件夹下的conf,然后打开tomcat-users.xml 在标签中加入 <user name="" password="" rol ...

  5. MVC之ActionFilterAttribute

    1.登录页面代码: @{ ViewBag.Title = "会员登录"; Layout = "~/Views/Shared/_LayoutDialog.cshtml&qu ...

  6. UVA 23 out of 5

    题目例如以下: Problem I 23 Out of 5 Input: standard input Output: standardoutput Time Limit: 1 second Memo ...

  7. UVa 11475 - Extend to Palindrome

    題目:給你一個字符串,在後面拼接一部分使得它變成回文串,使得串最短.輸出這個回文串. 分析:KMP,dp.這裡利用KMP算法將串和它的轉置匹配,看結束時匹配的長度就可以. 因為串比较長.使用KMP比较 ...

  8. IPV6相关RFC文档

    1. 通用 IPv6的通用RFC和Internet草案 RFC# 类 标题 1752 标准记录 对IP下一代协议的建议 1924 资料 IPv6地址的压缩表示法 2851 标准记录 Internet网 ...

  9. hdoj-1214-圆桌会议【逆序数】

    圆桌会议 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissi ...

  10. Eclipse下单个文件中文乱码问题

    有时候用eclipse打开单个文件,会出现中文乱码问题. 这时可以点菜单栏 Edit -> Set Encoding,Other:UTF-8,通常可以解决问题.