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 ...
随机推荐
- Yarn 的工作流-创建一个新项目
Microsoft Windows [版本 10.0.16299.125] (c) Microsoft Corporation.保留所有权利. C:\Users\Administrator>cd ...
- windows安装Python模块:requests
个人在windows10安装python模块requests如下过程: 1.下载requests模块:首先打开powershell, cd到你要下载文件的位置(我的是d:\softwareinstal ...
- 【EasyUI】——可编辑的DataGrid
利用EasyUI做的可编辑的DataGrid大致分为两种类型.一种是启动行编辑的,一种是启动单元格编辑.且不说启动编辑的效果怎样.单启动编辑这一块它就封装的非常厉害.好些功能没有办法去更改.如今项目的 ...
- debug 和release 的区别
http://blog.csdn.net/h_wlyfw/article/details/26688677
- Codeforces 690 C3. Brain Network (hard) LCA
C3. Brain Network (hard) Breaking news from zombie neurology! It turns out that – contrary to prev ...
- HDU 1724 Ellipse 【自适应Simpson积分】
Ellipse Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- H264 层次构成[2]
H264层次构成 H264标准是由JVT(Joint Video Team,视频联合工作组)组织提出的新一代数字视频编码标准.JVT于2001年12月在泰国Pattaya成立.它由ITU-T的VCEG ...
- html5 弹性布局
html5 弹性布局 一.移动开发常用技巧 Viewport基本知识 设置布局Viewport的各种信息1.width=device-width: 设置Viewport视口宽度等于设备宽度2.init ...
- Size Classes with Xcode 6:为所有的尺寸准备一个Storyboard
我最喜欢的Xcode6的特性是新的size classes 概念,有了它,我们解决了“我如何能够快速的为那么多不同尺寸屏幕以及方向的设备写app”.他们也让在一个storyboard中创建一个通用的a ...
- flask-migrate 数据迁移
作用:做数据库迁移依赖:flask-script flask-sqlalchemy 使用 项目结构 manage.py(其它文件内容与flask-sqlalchemy中一样) from s8day13 ...