题目链接:http://ac.jobdu.com/problem.php?pid=1452

详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus

参考代码:

//
// 1452 搬寝室.cpp
// Jobdu
//
// Created by PengFei_Zheng on 24/04/2017.
// Copyright © 2017 PengFei_Zheng. All rights reserved.
// #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cmath>
#include <limits.h>
//#define MAX 0x7fffffff
#define MAX_SIZE 2001
#define MAX_ROW 1001
using namespace std; int n, k; int weight[MAX_SIZE];
long long dp[MAX_ROW][MAX_SIZE]; int main(){
while(scanf("%d%d",&n,&k)!=EOF){
for(int i = ; i <= n ; i++){
scanf("%d",&weight[i]);
}
sort(weight+,weight++n);
for(int i = ; i <= n ; i++){
dp[][i]=;
}
for(int i = ; i <= k ; i++){
for(int j = *i ; j <= n ; j++){
if(j>*i){
dp[i][j] = dp[i][j-];
}
else
dp[i][j] = INT_MAX; if(dp[i][j] > dp[i-][j-]+pow(weight[j]-weight[j-],)){
dp[i][j] = dp[i-][j-]+pow(weight[j]-weight[j-],);
}
}
}
printf("%lld\n",dp[k][n]);
}
return ;
}
/**************************************************************
Problem: 1452
User: zpfbuaa
Language: C++
Result: Accepted
Time:50 ms
Memory:17176 kb
****************************************************************/

题目1452:搬寝室(dp题目)的更多相关文章

  1. 九度OJ 1452 搬寝室 -- 动态规划

    题目地址:http://ac.jobdu.com/problem.php?pid=1452 题目描述: 搬寝室是很累的,xhd深有体会.时间追述2006年7月9号,那天xhd迫于无奈要从27号楼搬到3 ...

  2. hdu---(1421)搬寝室(dp)

    搬寝室 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  3. hdu-1421搬寝室(dp)

    http://acm.hdu.edu.cn/showproblem.php?pid=1421; 思路:先将所给的椅子的价值按升序排列,举个例子,四张椅子的价值分别为a,b,c,d(a<b< ...

  4. hdu1421 搬寝室 DP

    转载: /*证明:从4个数中 a b c d  依次递增: 选取相邻的两个数一定是最小得 及:(a-b)^2+(c-d)^2<(a-c)^2+(b-d)^2&&(a-b)^2+( ...

  5. hdu1421_搬寝室

    题目:搬寝室 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1421 #include<stdio.h> #include<algor ...

  6. 九度oj 题目1452:搬寝室

    题目描述: 搬寝室是很累的,xhd深有体会.时间追述2006年7月9号,那天xhd迫于无奈要从27号楼搬到3号楼,因为10号要封楼了.看着寝室里的n件物品,xhd开始发呆,因为n是一个小于2000的整 ...

  7. dp题目

    从别的地方看来,最近一直在啃DP,有个目标,更有动力了. 1.Robberies 连接 :http://acm.hdu.edu.cn/showproblem.php?pid=2955      背包; ...

  8. 搬寝室(经典dp)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1421 hdu_1421:搬寝室 Time Limit: 2000/1000 MS (Java/Othe ...

  9. HDU-1421 搬寝室【dp】

    题目链接:https://vjudge.net/contest/214662#problem/E 题目大意:                                               ...

随机推荐

  1. spring cloud feign 上传文件报not a type supported by this encoder解决方案

    上传文件调用外部服务报错: not a type supported by this encoder 查看SpringFormEncoder类的源码: public class SpringFormE ...

  2. u3d animation运用明细

    u3d的动作legacy模式,经测试得出 using UnityEngine; using System.Collections; public class AnimateCon : MonoBeha ...

  3. dpkg: error processing package libraspberrypi-doc (--configure): package is in a very bad inconsistent state;

    dpkg: error processing package libraspberrypi-doc (--configure): package is in a very bad inconsiste ...

  4. asp.net gridview实现正在加载效果方案一AJAX(转)

    前台代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.as ...

  5. 简单理解AOP(面向切面编程)

    AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术. AOP与OOP是面向不同领域的两种设计思想. ...

  6. 举例理解Hibernate的三种状态

    初学Hibernate,了解到Hibernate有三种状态:transient(瞬时状态),persistent(持久化状态)以及detached(游离状态). 它们之间有如下转换图来说明: 1.tr ...

  7. ClangFormat代码格式化

    下载地址:https://github.com/travisjeffery/ClangFormat-Xcode 配合Xcode自带的格式化操作,就很不错了 选中内容组合操作: 第一步:ClangFor ...

  8. 【项目管理】Project使用

    http://www.cnblogs.com/wangfupeng1988/p/3647166.html

  9. ul li列表元素浮动导致border没有底边解决办法

    如图,当ul li,li元素浮动,并且ul元素也overflow:hidden清除浮动的时候,给li元素加了border,但是不显示底边,这时候要看是不是没有给li元素加高,因为加了border之后默 ...

  10. Windbg在软件调试中的应用

    Windbg在软件调试中的应用 Windbg是微软提供的一款免费的,专门针对Windows应用程序的调试工具.借助于Windbg, 我们常见的软件问题:软件异常,死锁,内存泄漏等,就可以进行高效的排查 ...