Building Shops 
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) 
Total Submission(s): 701 Accepted Submission(s): 265

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 

1 2 
2 3 
3 4 

1 7 
3 1 
5 10 
6 1

Sample Output 

11

Source 
2017中国大学生程序设计竞赛 - 女生专场

题意: 
有n个教室,现在想在这n个教室中建一些超市,问你最少费用为多少? 
费用分为两种: 
1:在第i个教室建超市,费用因为ci 
2:没有建超市的教室的费用为它和它左边最接近的超市的坐标之间的距离

#include <iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<deque>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
struct node
{
ll x;
ll c;
}a[];
bool cmp(node x,node y)
{
return x.x<y.x;
}
ll dp[];
//dp[i]表示只考虑前i个教室 的最优解
ll dp2[];
//dp2[i]表示 第i个固定条件下,前i个的最优解
ll s[];
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=;i<=n;i++)
{
scanf("%lld %lld",&a[i].x,&a[i].c); }
sort(a+,a+n+,cmp);
memset(dp,inf,sizeof(dp));
memset(dp2,inf,sizeof(dp2));
memset(s,,sizeof(s));
dp[]=;
dp[]=dp2[]=a[].c;
int pp=a[].x;
for(int i=;i<=n;i++)
{
a[i].x-=pp;
s[i]=a[i].x+s[i-];
}
for(int i=;i<=n;i++)
{
dp2[i]=dp[i-]+a[i].c;
//第i个固定条件下,前i个的最优解
for(int j=;j<=i;j++)
{
dp[i]=min(dp[i],dp2[j]+s[i]-s[j]-(i-j)*a[j].x);
}
}
printf("%lld\n",dp[n]);
}
return ;
}

Building Shops

Time
Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K
(Java/Others)
Total Submission(s): 2728    Accepted Submission(s):
936

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
 
Source
 
Recommend
jiangzijing2015   |   We have carefully selected
several similar problems for you:  6286 6285 6284 6283 6282 

2017中国大学生程序设计竞赛 - 女生专场(dp)的更多相关文章

  1. 2017中国大学生程序设计竞赛 - 女生专场 Deleting Edges(思维+最短路)

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

  2. 2017中国大学生程序设计竞赛 - 女生专场 Happy Necklace(递推+矩阵快速幂)

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

  3. 2017中国大学生程序设计竞赛 - 女生专场(Graph Theory)

    Graph Theory Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)To ...

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

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

  5. 2017中国大学生程序设计竞赛 - 女生专场B【DP】

    B HDU - 6024 [题意]:n个教室,选一些教室建造糖果商店. 每个教室,有一个坐标xi和在这个教室建造糖果商店的花费ci. 对于每一个教室,如果这个教室建造糖果商店,花费就是ci,否则就是与 ...

  6. 2017中国大学生程序设计竞赛 - 女生专场C【前后缀GCD】

    C HDU - 6025 [题意]:去除数列中的一个数字,使去除后的数列中所有数字的gcd尽可能大. [分析]: 数组prefixgcd[],对于prefixgcd[i]=g,g为a[0]-a[i]的 ...

  7. 2017中国大学生程序设计竞赛 - 女生专场A【模拟】

    A HDU - 6023 [题意]:求AC题数和总时长. [分析]:模拟.设置标记数组记录AC与否,再设置错题数组记录错的次数.罚时罚在该题上,该题没AC则不计入总时间,AC则计入.已经AC的题不用再 ...

  8. HDU 6024(中国大学生程序设计竞赛女生专场1002)

    这是CCPC女生专场的一道dp题.大佬们都说它简单,我并没有感到它有多简单. 先说一下题意:在一条直线上,有n个教室,现在我要在这些教室里从左到右地建设一些作为糖果屋,每个教室都有自己的坐标xi 和建 ...

  9. "巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场

    Combine String #include<cstdio> #include<cstring> #include<iostream> #include<a ...

随机推荐

  1. 分享:JAVA各种对象

    PO:持久对象 (persistent object),po(persistent object)就是在Object/Relation Mapping框架中的Entity,po的每个属性基本上都对应数 ...

  2. 如果在applicationContext.xml中没有配置bean的属性,那么也会导致空指针异常

    报错如下: java.lang.NullPointerException cn.itcast.action.VisitAction.toAddPage(VisitAction.java:37) sun ...

  3. svn官方版本的使用

    创建仓库的命令是:svndadmin create c:\abcde 启动命令是:svnserve -d -r c:\abcde 官方版本,svn路径

  4. Mac OS X下实现结束占用某特定端口的进程

    ---恢复内容开始--- 1.打开终端,使用如下命令: lsof -i:**** 以上命令中,****代表端口号,我们首先要知道哪个(或哪些)进程占用该端口,比如你可以运行 lsof -i:8000, ...

  5. RabbitMQ 资料整理

    前言: 官方教程: https://www.rabbitmq.com/getstarted.html 应用场景(之马云赚钱): http://blog.csdn.net/whoamiyang/arti ...

  6. <img>边框的border属性

    默认地,图像是没有边框的(除非图像在 a 元素内部). 浏览器通常会把代表超链接的图像(例如包含在 <a> 标签中的图像)显示在两个像素宽的边框里面,以表示读者可以通过选择这个图像来访问相 ...

  7. VMware安装VMwareTolls

    要先启动Ubuntu,用root用户进入. 然后点击VMware的虚拟机——设置——安装VMwareTools 桌面会有一个安装包,解压后,执行vmware-install.pl 安装需要等别以为是安 ...

  8. 条款24:如果所有的参数都需要类型转换,那么请为此采用non-member函数

    首先还是下面这个class; class Rational{ public: Rational(, ); int numurator() const; int denominator() const; ...

  9. UI- 不易记知识点汇总

    1.static: 所有的全局变量都是静态变量,而局部变量只有定义时加上类型修饰符static,才为局部静态变量. 静态变量并不是说其就不能改变值,不能改变值的量叫常量. 其拥有的值是可变的 ,而且它 ...

  10. VS2010 将程序发布至网站时,发生错误“未能给 bin/Debug/publish//setup.exe 签名“

    VS2010 将程序发布至网站时,发生错误“未能给 bin/Debug/publish//setup.exe 签名“  错误:   因为某项目未能生成,所以无法发布. ---------------- ...