2017中国大学生程序设计竞赛 - 女生专场 1002 dp
Building Shops
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
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.
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.
#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的更多相关文章
- 2017中国大学生程序设计竞赛 - 女生专场(dp)
Building Shops Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) To ...
- 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 ...
- HDU 6024(中国大学生程序设计竞赛女生专场1002)
这是CCPC女生专场的一道dp题.大佬们都说它简单,我并没有感到它有多简单. 先说一下题意:在一条直线上,有n个教室,现在我要在这些教室里从左到右地建设一些作为糖果屋,每个教室都有自己的坐标xi 和建 ...
- 2017中国大学生程序设计竞赛 - 女生专场C【前后缀GCD】
C HDU - 6025 [题意]:去除数列中的一个数字,使去除后的数列中所有数字的gcd尽可能大. [分析]: 数组prefixgcd[],对于prefixgcd[i]=g,g为a[0]-a[i]的 ...
- 2017中国大学生程序设计竞赛 - 女生专场B【DP】
B HDU - 6024 [题意]:n个教室,选一些教室建造糖果商店. 每个教室,有一个坐标xi和在这个教室建造糖果商店的花费ci. 对于每一个教室,如果这个教室建造糖果商店,花费就是ci,否则就是与 ...
- 2017中国大学生程序设计竞赛 - 女生专场A【模拟】
A HDU - 6023 [题意]:求AC题数和总时长. [分析]:模拟.设置标记数组记录AC与否,再设置错题数组记录错的次数.罚时罚在该题上,该题没AC则不计入总时间,AC则计入.已经AC的题不用再 ...
- "巴卡斯杯" 中国大学生程序设计竞赛 - 女生专场
Combine String #include<cstdio> #include<cstring> #include<iostream> #include<a ...
随机推荐
- MAC终端安装指定版本node
MAC终端安装指定版本node 安装brew 终端上运行 $ /usr/bin/ruby -e “$(curl -fsSL https://raw.githubusercontent.com/Home ...
- Prometheus+Grafana监控部署实践
参考文档: Prometheus github:https://github.com/prometheus grafana github:https://github.com/grafana/graf ...
- CentOS-6.x系列查看cpu核数
使用CentOS7.x使用习惯了后用top命令,然后按1就可以查看相关的cpu核心数等相关信息 相关概念: 物理CPU:实际Server中插槽上的CPU个数. 物理cpu数量:可以数不重复的 phys ...
- phpquery 学习笔记
phpQuery是一个基于PHP的服务端开源项目,它可以让PHP开发人员轻松处理DOM文档内容,比如获取某新闻网站的头条信息.更有意思的是,它采用了jQuery的思想,你可以像使用jQuery一样处理 ...
- 查看struts包源码
- CDOJ ABCDE dp(前缀和优化)
题目链接: http://acm.uestc.edu.cn/#/problem/show/1307 ABCDE Time Limit: 1000/1000MS (Java/Others)Memory ...
- HDU 5496 Beauty of Sequence
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5496 Beauty of Sequence Problem Description Sequence ...
- TCP系列51—拥塞控制—14、TLP、ER与拥塞控制
一.概述 这里的重点是介绍TLP.ER与拥塞控制并不是介绍TLP和ER本身,因此TLP和ER的详细内容请翻前文. 在TLP与拥塞控制的交互中有几个点需要注意 1.TLP触发的重传后,TCP仍然处于Op ...
- 解决svn "cannot set LC_CTYPE locale"的问题
解决svn "cannot set LC_CTYPE locale"的问题 在ubuntu 8.10下安装的svn,在将Ubuntu的语言修改为英文之后,出现错误警告: $ svn ...
- Kafka发布订阅消息
Maven <dependency> <groupId>org.apache.kafka</groupId> <artifactId>kafka-cli ...