hdu 1421
时隔多日,又回来啃dp...
题意:有n件物品,搬k次,每搬一个消耗的疲劳值为两件物品重量之差的平方,求最小的疲劳消耗
状态转移方程:dp[i][j] = min((dp[i-2][j-1]+(s[i]-s[i-1])*(s[i]-s[i-1])),dp[i-1][j]);
dp[i][j]表示有i个物品时j次搬运最小的疲劳值
#include<iostream>
#include<cstdio>
#include<algorithm> using namespace std; #define INIT 2147483646 int dp[2222][1111]; int main(){
int i,j,k,n;
int s[2222] = {0};
while(cin>>n>>k){
for(i=1;i<=n;i++)
scanf("%d",s+i);
sort(s+1,s+n+1);
dp[0][0] = 0;
for(i=0;i<=n;i++)
for(j=1;j<=k;j++)
dp[i][j] = INIT;
for(i=2;i<=n;i++)
for(j=1;j*2<=i;j++)
dp[i][j] = min((dp[i-2][j-1]+(s[i]-s[i-1])*(s[i]-s[i-1])),dp[i-1][j]);
cout<<dp[n][k]<<endl;
}
return 0;
}
hdu 1421的更多相关文章
- hdu 1421:搬寝室(动态规划 DP + 排序)
搬寝室 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- DP问题(2) : hdu 1421
题目转自hdu 1421,题目传送门 题目大意: 给你n个物品,你要搬走2*k个(也就是搬k次) 每次搬需要花费v,v=(ai-aj)2 (i表示左手拿的物品重量,j表示右手拿的物品的重量) 要求所有 ...
- 【dp】HDU 1421 搬寝室
http://acm.hdu.edu.cn/showproblem.php?pid=1421 [题意] 给定n个数,要从n个数中选择k个二元组{x,y},最小化sum{(x-y)^2} 2<=2 ...
- 题解报告:hdu 1421 搬寝室(递推dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1421 Problem Description 搬寝室是很累的,xhd深有体会.时间追述2006年7月9 ...
- HDU 1421 搬寝室 (线性dp 贪心预处理)
搬寝室 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- [HDU 1421]搬寝室(富有新意的DP)
题目地址:pid=1421" target="_blank">http://acm.hdu.edu.cn/showproblem.php? pid=1421 题目大 ...
- HDU 1421 搬寝室
搬寝室 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- HDU 1421 DP
搬寝室 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- 搬寝室(HDU 1421 DP)
搬寝室 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
随机推荐
- SqlSever基础 dateadd month 增加五个月
镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...
- 我的android学习经历15
利用Intent实现有返回结果的页面跳转 主要用的方法: (1)Intent的构造方法:intent(当前界面对象,要跳转的界面.class); (2)接受结果的方法onActivityResult( ...
- BZOJ 3085: 反质数加强版SAPGAP (反素数搜索)
题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3085 题意:求n(<=10^100)之内最大的反素数. 思路: 优化2: i ...
- C++实现二叉树,运用模板,界面友好,操作方便 运行流畅
//.h文件 #ifndef TREE_H #define TREE_H #include<iostream> #include<iomanip> using namespac ...
- js表单操作
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- TortoiseGit中push的使用
https://tortoisegit.org/docs/tortoisegit/tgit-dug-push.html Options Force (May discard known changes ...
- Codeforces Round #261 (Div. 2) B
链接:http://codeforces.com/contest/459/problem/B B. Pashmak and Flowers time limit per test 1 second m ...
- Spark Streaming官方文档学习--上
官方文档地址:http://spark.apache.org/docs/latest/streaming-programming-guide.html Spark Streaming是spark ap ...
- Codeforces Round #377 (Div. 2) C. Sanatorium 水题
C. Sanatorium time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 《Linux内核设计的艺术》学习笔记(二)INT 0x13中断
参考资料: 1. <IBM-PC汇编语言程序设计> 2. http://blog.sina.com.cn/s/blog_5028978101008wk2.html 3. http://ww ...