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. 搭建RTSP服务器时nginx的nginx.conf文件配置

    worker_processes 1; events { worker_connections 1024;} http { include mime.types; default_type appli ...

  2. Teaching Machines to Understand Us 让机器理解我们 之三 自然语言学习及深度学习的信仰

    Language learning 自然语言学习 Facebook’s New York office is a three-minute stroll up Broadway from LeCun’ ...

  3. Python 日志记录与程序流追踪(基础篇)

    日志记录(Logging) More than print: 每次用 terminal debug 时都要手动在各种可能出现 bug 的地方 print 相关信息来确认 bug 的位置: 每次完成 d ...

  4. Hands on Machine Learning with sklearn and TensorFlow —— 一个完整的机器学习项目(加州房地产)

    数据集地址:https://github.com/ageron/handson-ml/tree/master/datasets 先行知识准备:NumPy,Pandas,Matplotlib的模块使用 ...

  5. 剑指 Offer——和为 S 的连续正数序列

    1. 题目 2. 解答 定义两个指针,刚开始分别指向 1 和 2,求出位于这两个指针之间的元素和.如果和大于 S,前面的指针向后移直到和不大于 S 为止:反之,如果和等于 S,则此时两个指针之间的元素 ...

  6. leetcode个人题解——#31 Next Permutation

    写这题时脑子比较混乱,重写了一遍wiki大佬的解法. 算法: According to Wikipedia, a man named Narayana Pandita presented the fo ...

  7. 城联数据TSM技术方案起底

    近日,城联数据有限公司与中国电信签订了<基于NFC技术的公交业务的合作协议>.双方基于NFC技术开展互联互通城市公交卡业务合作,实现符合住房和城乡建设部城市公用事业互联互通卡系列标准的移动 ...

  8. OpenCV学习笔记——imread、imwrite以及imshow

    1.imread Loads an image from a file. 从文件中读取图像. C++: Mat imread(const string& filename, int flags ...

  9. 博弈---ZOJ 2083 Win the Game(染绳子)

    原题:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2083 大意:两个人分别对n条绳子染 每次染m长 最后染不下的输,问先 ...

  10. HDU 5191 Building Blocks

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5191 bc(中文):http://bestcoder.hdu.edu.cn/contests ...