2017中国大学生程序设计竞赛 - 女生专场(dp)
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
3
1 2
2 3
3 4
4
1 7
3 1
5 10
6 1
Sample Output
5
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
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.
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
,c
i
(−10
9
≤x
i
,c
i
≤10
9
)
, 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.
integer, denoting the minimal cost.
1 2
2 3
3 4
4
1 7
3 1
5 10
6 1
11
several similar problems for you: 6286 6285 6284 6283 6282
2017中国大学生程序设计竞赛 - 女生专场(dp)的更多相关文章
- 2017中国大学生程序设计竞赛 - 女生专场 Deleting Edges(思维+最短路)
Deleting Edges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 2017中国大学生程序设计竞赛 - 女生专场 Happy Necklace(递推+矩阵快速幂)
Happy Necklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 2017中国大学生程序设计竞赛 - 女生专场(Graph Theory)
Graph Theory Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)To ...
- 2017中国大学生程序设计竞赛 - 女生专场 1002 dp
Building Shops Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 2017中国大学生程序设计竞赛 - 女生专场B【DP】
B HDU - 6024 [题意]:n个教室,选一些教室建造糖果商店. 每个教室,有一个坐标xi和在这个教室建造糖果商店的花费ci. 对于每一个教室,如果这个教室建造糖果商店,花费就是ci,否则就是与 ...
- 2017中国大学生程序设计竞赛 - 女生专场C【前后缀GCD】
C HDU - 6025 [题意]:去除数列中的一个数字,使去除后的数列中所有数字的gcd尽可能大. [分析]: 数组prefixgcd[],对于prefixgcd[i]=g,g为a[0]-a[i]的 ...
- 2017中国大学生程序设计竞赛 - 女生专场A【模拟】
A HDU - 6023 [题意]:求AC题数和总时长. [分析]:模拟.设置标记数组记录AC与否,再设置错题数组记录错的次数.罚时罚在该题上,该题没AC则不计入总时间,AC则计入.已经AC的题不用再 ...
- HDU 6024(中国大学生程序设计竞赛女生专场1002)
这是CCPC女生专场的一道dp题.大佬们都说它简单,我并没有感到它有多简单. 先说一下题意:在一条直线上,有n个教室,现在我要在这些教室里从左到右地建设一些作为糖果屋,每个教室都有自己的坐标xi 和建 ...
- "巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场
Combine String #include<cstdio> #include<cstring> #include<iostream> #include<a ...
随机推荐
- Mongodb笔记(三)user && aggregate && mapReduce
版本:mongodb3.4. User: mongodb使用验证登录:默认不开启,mongod中使用--auth开启: mongod -port=3000 --auth : 基本方法: db.cr ...
- Tavas and Karafs 二分+结论
二分比较容易想到 #include<map> #include<set> #include<cmath> #include<queue> #includ ...
- 21-THREE.JS 将法线矢量映射到RGB颜色的材质
<!DOCTYPE html> <html> <head> <title></title> <script src="htt ...
- Oracle11g数据库监听配置
(转自:http://blog.sina.com.cn/s/blog_6908928501018057.html) 经验告诉我:最好把数据库的SID和数据库全局名称分开,免得配置时混了,如果要配置服务 ...
- 配置 Web 组件服务器 IIS 证书
用 IIS 6 配置 Web 组件证书(对于 Windows Server 2003) 使用 IIS 管理器向 Web 组件服务器分配证书.对合并池配置中的 Standard Edition ...
- EL表达式自定义函数
表达式语言除了可以使用基本的运算符外,还可以使用自定义函数.通过使用自定义函数,加强了表达式语言的功能. EL表达式函数,主要功能是完成对数据的修改,统一化格式: 步骤 1.开发函数处理类,处理类就是 ...
- Django restfull规范
一. 什么是RESTful REST与技术无关,代表的是一种软件架构风格,REST是Representational State Transfer的简称,中文翻译为“表征状态转移” REST从资源的角 ...
- Android studio 导入ApiDemo
1.import 项目,sdk目录:sdk\samples\android-21\legacy\ApiDemos,import时一直下一步就ok了. 2.Error:Error: The file n ...
- [Scala]Scala学习笔记一 基础
1. 变量 val定义的值实际上是一个常亮,无法改变其内容 scala> val num = 0 num: Int = 0 scala> num = 2 <console>:1 ...
- 测试中认识 sqlite
1.SQLite,是一款轻型的数据库:简单, 轻松的API 单词速记中单词离线包也用到sqlite 百度了一下,基本的使用语句: .help .quit sqlite3 testDB.db 在当前目录 ...