HDU_1421_搬寝室_dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1421
搬寝室
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 23904 Accepted Submission(s): 8177
1 3
if(j*<=i-) dp[i][j]=min(dp[i-][j],dp[i-][j-]+(weight[i]-weight[i-])*(weight[i]-weight[i-]));
else dp[i][j]=dp[i-][j-]+(weight[i]-weight[i-])*(weight[i]-weight[i-]); //不可能从前i-1个中拿出j对
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
//#define INF 9223372036854775807
#define LL long long
LL weight[];
LL dp[][]; ///前i个中找j对的最小值
int main()
{
int n,k;
while(scanf("%d%d",&n,&k)!=EOF)
{
for(int i=; i<=n; i++)
scanf("%I64d",&weight[i]);
sort(weight+,weight+n+);
for(int i=; i<=n; i++)
for(int j=; *j<=i; j++)
{
if(j*<=i-)
dp[i][j]=min(dp[i-][j],dp[i-][j-]+(weight[i]-weight[i-])*(weight[i]-weight[i-]));
else
dp[i][j]=dp[i-][j-]+(weight[i]-weight[i-])*(weight[i]-weight[i-]);
}
printf("%I64d\n",dp[n][k]);
}
return ;
}
HDU_1421_搬寝室_dp的更多相关文章
- B - 搬寝室
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Pract ...
- hdu---(1421)搬寝室(dp)
搬寝室 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- HDU 1421 搬寝室
搬寝室 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- 九度OJ 1452 搬寝室 -- 动态规划
题目地址:http://ac.jobdu.com/problem.php?pid=1452 题目描述: 搬寝室是很累的,xhd深有体会.时间追述2006年7月9号,那天xhd迫于无奈要从27号楼搬到3 ...
- 搬寝室(HDU 1421 DP)
搬寝室 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- hdu 1421 搬寝室(dp)
Problem Description 搬寝室是很累的,xhd深有体会.时间追述2006年7月9号,那天xhd迫于无奈要从27号楼搬到3号楼,因为10号要封楼了.看着寝室里的n件物品,xhd开始发呆, ...
- 搬寝室 hdu
Problem Description 搬寝室是很累的,xhd深有体会.时间追述2006年7月9号,那天xhd迫于无奈要从27号楼搬到3号楼,因为10号要封楼了.看着寝室里的n件物品,xhd开始发呆, ...
- 搬寝室(经典dp)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1421 hdu_1421:搬寝室 Time Limit: 2000/1000 MS (Java/Othe ...
- hdu1421_搬寝室
题目:搬寝室 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1421 #include<stdio.h> #include<algor ...
随机推荐
- ios7 UIBarButtonItem 默认蓝色
[self.navigationItem setLeftBarButtonItem:leftButton]; 这样设置在ios7上button默认是蓝色 解决方法: leftButton.tintCo ...
- 2015/12/29 Java语言概述 操作中注意事项
java语言概述 ①版本分类:JavaSE 标准版 桌面开发 JavaEE 企业版 网络开发 JavaME 移动版 嵌入式开发(塞班系统 ...
- 【LIS】Luogu P1020 导弹拦截
昨天晚上看蓝书,看到了LIS问题的优化解法. 是比O(n方)更快的解法,实际上是一个常数优化. 先讲一下朴素的解法: 一个集合a,a[i]是第i个元素.设dp[i]为以编号为i的元素结尾的最长不上升子 ...
- 谈谈C++私有继承
很多C++程序猿从来没用过私有继承来设计他的类.的确,假设是本该用私有继承的地方却用了公有继承.对程序的功能的实现并无影响. 但这样的误用是一种错位的描写叙述.会引起阅读者的误解,甚至会引起类的使用者 ...
- go1
关键字: break default func interface select case defer go map struct chan else goto package switch cons ...
- USACO Section 1.1PROB Your Ride Is Here
题目传送门 不能提交哦 http://www.nocow.cn/index.php/Translate:USACO/ride /* ID: jusonal1 PROG: ride LANG: C+ ...
- Opencv+Zbar二维码识别(二维码校正)
二维码和车牌识别基本都会涉及到图像的校正,主要是形变和倾斜角度的校正,一种二维码的畸变如下图: 这个码用微信扫了一下,识别不出来,但是用Zbar还是可以准确识别的~~. 这里介绍一种二维码校正方法,通 ...
- Java序列化系列教程(上)
一定义以及相关概念 互联网的产生带来了机器间通讯的需求,而互联通讯的双方需要采用约定的协议,序列化和反序列化属于通讯协议的一部分.通讯协议往往采用分层模型,不同模型每层的功能定义以及颗粒度不同,例如: ...
- render same axis
// 当前渲染相机的参数 QGlobalCamera* curRenderCamera = _getWorld()->getMainCam(); const Matrix4& ...
- Unity ScriptObject
http://godstamps.blogspot.com/2012/02/unity-3d-scriptableobject-assetbundle.html http://ivanozanchet ...