Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 379    Accepted Submission(s): 144

Problem Description

HDU’s n classrooms are on a line ,which can be considered as a number line. Each classroom has a coordinate. Now Little Q wants to build several candy shops in these n classrooms.

The total cost consists of two parts. Building a candy shop at classroom i would have some cost ci. For every classroom P without any candy shop, then the distance between P and the rightmost classroom with a candy shop on P's left side would be included in the cost too. Obviously, if there is a classroom without any candy shop, there must be a candy shop on its left side.

Now Little Q wants to know how to build the candy shops with the minimal cost. Please write a program to help him.

Input

The input contains several test cases, no more than 10 test cases.
In each test case, the first line contains an integer n(1≤n≤3000), denoting the number of the classrooms.
In the following n lines, each line contains two integers xi,ci(−109≤xi,ci≤109), denoting the coordinate of the i-th classroom and the cost of building a candy shop in it.
There are no two classrooms having same coordinate.

Output

For each test case, print a single line containing an integer, denoting the minimal cost.

Sample Input

3
1 2
2 3
3 4
4
1 7
3 1
5 10
6 1

Sample Output

5

11

// 一条直线上有 n 的教室,想要在这些点上建一些糖果店,建设糖果店的成本分为 2 部分,建设费,右边的非糖果店到这个糖果店的距离差的和(累加到是一个糖果店为止)

//典型DP题

dp[i] 为在 i 建造最后一个糖果店的最小花费的话

丛左到右 dp[i] = min(dp[i],dp[j]+shop[i].v-(n-i+1)*(shop[i].p-shop[j].p)) (1<=j<i) p是位置,v为建造费

还有就是需要排序,还有需要 long long 型

 #include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define LL long long
#define MX 3005
struct Shop
{
LL p,v;
bool operator < (const Shop& b)const
{
return p<b.p;
}
}shop[MX];
LL dp[MX]; int main()
{
int n;
while (scanf("%d",&n)!=EOF)
{
for (int i=;i<=n;i++)
scanf("%I64d%I64d",&shop[i].p,&shop[i].v);
sort(shop+,shop++n);
LL total = ;
for (int i=;i<=n;i++)
total += shop[i].p - shop[].p; dp[]=shop[].v+total;
for (int i=;i<=n;i++)
{
for (int j=;j<i;j++)
{
if (j==) dp[i] = dp[j] + shop[i].v - (n-i+)*(shop[i].p-shop[j].p);
else dp[i] = min(dp[i],dp[j]+shop[i].v-(n-i+)*(shop[i].p-shop[j].p));
}
}
LL ans = dp[];
for (int i=;i<=n;i++)
ans = min(dp[i],ans);
printf("%I64d\n",ans);
}
return ;
}

Building Shops的更多相关文章

  1. HDU6024 Building Shops 2017-05-07 18:33 30人阅读 评论(0) 收藏

    Building Shops                                                             Time Limit: 2000/1000 MS ...

  2. HDU6024:Building Shops(简单DP)

    Building Shops Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  3. (hdu 6024) Building Shops

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6024 Problem Description HDU’s n classrooms are on a ...

  4. hdu6024 Building Shops(区间dp)

    https://cn.vjudge.net/problem/HDU-6024 分开考虑某一点种与不种,最后取二者的最小值. dp[i][1] = min(dp[i-1][0], dp[i-1][1]) ...

  5. HDU 6024 Building Shops

    $dp$. $dp[i]$表示到$i$位置,且$i$位置建立了的最小花费,那么$dp[i] = min(dp[k]+cost[i+1][k-1])$,$k$是上一个建的位置.最后枚举$dp[i]$,加 ...

  6. 【HDU6024】Building Shops

    题意 有n个教室排成一排,每个教室都有一个坐标,现在,小Q想建一些糖果商店,在这n个教室里面.总的花费有两部分,在教室i建一个糖果屋需要花费ci,对于没有任何糖果屋的P,需要的花费为这个教室到它左边有 ...

  7. HDU6024:Building Shops(DP)

    传送门 题意 在一条直线上有n个教室,现在要设置糖果店,使得最后成本最小,满足以下两个条件: 1.若该点为糖果店,费用为cost[i]; 2.若不是,则为loc[i]-最近的糖果店的loc 分析 dp ...

  8. HDU 6024 Building Shops (简单dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6024 题意:有n个room在一条直线上,需要这这些room里面建造商店,如果第i个room建造,则要总 ...

  9. 2017中国大学生程序设计竞赛 - 女生专场 1002 dp

    Building Shops Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

随机推荐

  1. 【微信转载】Google是如何做测试的

    就 目前的软件公司而言,Google无疑是在开放和创新力方面做得最好的.而如何支撑Google这种快速地扩张的研发能力以及迭代速度,并且产品质量总是 一如以往的能给人们很棒的用户体验?这是一个值得我们 ...

  2. vue 预渲染 prerender-spa-plugin

    1.预渲染说明 https://ssr.vuejs.org/zh/#为什么使用服务器端渲染-ssr-? 如果你调研服务器端渲染(SSR)只是用来改善少数营销页面(例如 /, /about, /cont ...

  3. PNP管理器简析--基于ReactOS0.33

    CSDN上转悠了一圈发现关于PNP管理的文章不多.那就由我献个丑,记录自己对PNP管理器的看法. pnp管理器被描写叙述为向内核和应用程序提供关于设备拔插的通知,凭感觉,pnp管理器应该是个线程函数等 ...

  4. Python 的基本运算和内置函数

    一.运算符 (一)Python算术运算符 以下假设变量: a=10,b=20: 运算符 描述 实例 + 加 - 两个对象相加 a + b 输出结果 30 - 减 - 得到负数或是一个数减去另一个数 a ...

  5. python的threading和multiprocessing模块初探

    转载于:http://blog.csdn.net/zhaozhi406/article/details/8137670

  6. HTML5事件-自定义右键菜单

    WEB领域中,为实现上下文菜单,开发人员面临的主要问题是如何确定应该显示这个上下文菜单(Windows 中,右键单击:Mac 中,Ctrl+单击), 以及如何屏蔽与该操作相关联的默认上下文菜单. 解决 ...

  7. iOS Framework: Introducing MKNetworkKit

    MKNetworkKit介绍,入门.翻译 这片文章也有塞尔维亚-克罗地亚语(由Jovana Milutinovich翻译)和日语(由@noradaiko翻译)  假设有个一个网络库可以自己主动的为你处 ...

  8. Android WebView 开发具体解释(三)

    转载请注明出处   http://blog.csdn.net/typename/article/details/40302351 powered by miechal zhao 概览 Android ...

  9. nodejs 命令行获取入参

    安装:npm install yargs --save-dev Example index.js const argv = yargs.alias('n', 'name').alias('p', 'p ...

  10. Atitit.编程语言原理---方法重载的实现与设计 调用方法的原理

    Atitit.编程语言原理---方法重载的实现与设计 调用方法的原理 1. 重载包括:普通方法的重载和构造方法的重载 1 1.1. 横向重载”和“纵向重载”1 1.2. 方法签名通过  方法名称,参数 ...