Building Shops

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

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   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个教室的坐标和 当前教室建造糖果商店的代价  若当前教室不建造糖果商店则代价为 与左边最近的糖果商店的距离 第一个位置上的教室必然建造糖果商店 问最少的代价。
题解:dp[i][1]表示第i个教室建造糖果商店 前i个教室的最小代价,dp[i][2]表示第i个教室不建造糖果商店 前i个教室的最小代价,具体看代码。HDU 注意while多组输入 orz。
 

 #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define esp 0.00000000001
struct node
{
ll x;
ll c;
} N[];
bool cmp(struct node a,struct node b)
{
return a.x<b.x;
}
ll dp[][];
ll sum[];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=; i<=n; i++)
scanf("%I64d %I64d",&N[i].x,&N[i].c);
sort(N+,N++n,cmp);
for(int i=; i<=n; i++)
{
dp[i][]=5e18;
dp[i][]=5e18;
}
dp[][]=;
dp[][]=;
for(int i=; i<=n; i++)
{
dp[i][]=min(dp[i-][],dp[i-][])+N[i].c;
ll exm=;
for(int j=i-; j>=; j--)
{
exm=exm+(i-j)*(N[j+].x-N[j].x);//累加距离
dp[i][]=min(dp[i][],dp[j][]+exm);
}
}
printf("%I64d\n",min(dp[n][],dp[n][]));
}
return ;
}

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

  1. 2017中国大学生程序设计竞赛 - 女生专场(dp)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. String、StringBuffer、StringBuilder有什么区别

    区别 先说说String和StringBuffer/StringBuilder: String是标准的不可变类,是一个字符串常量池,并且声明的对象在方法中是唯一存在的. StringBuffer/St ...

  2. nodejs的路径问题

    最近公司的一个开发项目,后端用的是nodejs.这两天需要打包给客户演示,就让公司一个小伙把之前3D机房的打包工具移植过来.打包之后,发现原本在开发环境下的跑的好好的项目,不能访问了.出现项目的首页不 ...

  3. 如何选择 .NET Framework目标版本

    如何选择 .NET Framework目标版本 简介 .NET Framework是所有 .NET程序赖以运行的基础. 版本 到目前位置 .NET Framework共出了: .NET Framewo ...

  4. 网络流小结(HNOI2019之前)

    \(\text{一:Dinic最大流}\) 最坏复杂度 \({\mathcal O(n^2m)}\) 一般可以处理 \(10^4\) ~ \(10^5\) 的网络. struct Edge { int ...

  5. springmvc 静态资源 配置

    SpringMVC提供<mvc:resources>来设置静态资源,但是增加该设置如果采用通配符的方式增加拦截器的话仍然会被拦截器拦截,可采用如下方案进行解决: 方案一.拦截器中增加针对静 ...

  6. [C++] Solve "No source available for main()" error when debugging on Eclipse

    In Mac, the issue image: 1. A existing cmake project on disk 2. import this project into Eclipse. 3 ...

  7. Scrum立会报告+燃尽图(十月三十日总第二十一次)

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2290 项目地址:https://git.coding.net/zhang ...

  8. 作业要求20181016-3 Alpha阶段第1周/共2周 Scrum立会报告+燃尽图 01

    此次作业要求参见https://edu.cnblogs.com/campus/nenu/2018fall/homework/2246 Scrum master:范洪达 一.小组介绍 组长:王一可 组员 ...

  9. “Hello World!”团队第十四次会议

    今天是我们团队“Hello World!”团队召开的第十四次会议.博客内容: 一.会议时间 二.会议地点 三.会议成员 四.会议内容 五.Todo List 六.会议照片 七.燃尽图 一.会议时间 2 ...

  10. 基于spec探路者团队贪吃蛇作品的评论

    1 运动功能 由以上两图贪吃蛇的位置不同可知,运动功能实现.并且我能够通过使用键盘上的上下左右方位键控制蛇的移动方向,蛇在控制的方向上进行直线前进. 2 吃食物功能 以上两图可知吃食物功能实现.当界面 ...