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. Linux内核学习笔记(5)-- 进程调度概述

    进程调度程序是多任务操作系统的基础,它是确保进程能有效工作的一个内核子系统,负责决定哪个进程投入运行.何时运行以及运行多长时间.只有通过进程调度程序的合理调度,系统资源才能够最大限度地发挥作用,多进程 ...

  2. 记因内核版本错误导致U盘不能识别的问题解决

    U盘插上电脑,发现没有自动挂载.然后运行sudo fdisk -l一看,发现并没有U盘所对应的设备,也就是U盘不能识别了!以前从没在Linux上遇到这种问题,通过查资料得知,要识别U盘,需要装载usb ...

  3. 机器学习之决策树(ID3)算法

    最近刚把<机器学习实战>中的决策树过了一遍,接下来通过书中的实例,来温习决策树构造算法中的ID3算法. 海洋生物数据:   不浮出水面是否可以生存 是否有脚蹼 属于鱼类 1 是 是 是 2 ...

  4. Amazon Headlines Update on Activity in US West Coast Ports

    According to news reports, freighter cargo may not be offloaded at U.S. West Coast ports from Februa ...

  5. CSS布局之圣杯布局和双飞翼布局

    其实圣杯布局和双飞翼布局实现的都是三栏布局,两边的盒子宽度固定,中间盒子自适应,也就是我们常说的固比固布局.它们实现的效果都是一样的,差别在于其实现的思想. 一.圣杯布局 html代码中,将重要的内容 ...

  6. sprint3最终演示及团队贡献分

    团队名:在考虑 团队项目:复利计算 项目演示: 之前的功能都有演示过就不再一一截图,把我们新增加的功能说一下 首先用户进入我们的网页可以登录或者注册,注册的用户可以直接输入用户名及密码登录,没有注册的 ...

  7. 20135313_exp4

    实验四      GUI界面的设计和运用 20135313吴子怡 一.实验目的 结合项目,为每个密码学算法设计能够提供使用者用户体验的操作界面,实现加解密.求得消息摘要的功能. 二.代码举例(备注:其 ...

  8. Notepad++如何多视图(分屏)显示

    Notepad++ v6.6.7 当需要同时查阅或者编辑多个文件时,正是多视图功能大显身手的时候. 可以在你想要在另一边预览操作的文件名字(在工具栏和文件内容之间)上,单击右键,如下图所示,选择移动到 ...

  9. 把a文件删除b文件中的相同的行

    grep -vxFf b.txt a.txt > newa.txt 更好的方法是 comm - - b.txt a.txt > newa.txt 来自Tool in unix to sub ...

  10. 软工alpha阶段个人总结

    一.个人总结 类别 具体技能和面试问题 现在的回答(大三下) 语言 最拿手的语言之一,代码量是多少? java,代码量在一万行左右 语言 最拿手的语言之二,代码量是多少? C语言,代码量在五千行左右 ...