当前位置:网站首页>HDU - 6024 building shops (girls' competition)
HDU - 6024 building shops (girls' competition)
2022-07-06 16:03:00 【It's Xiao Zhang, ZSY】
C - Building Shops
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 ii 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 nn lines, each line contains two integers xi,ci(1e-9<=xi,ci<=1e9), denoting the coordinate of the ii-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
Broken thoughts , I wanted to write about dp That's it , Last time because dp Can't , It affects me to win the prize, woo woo , My registration fee
dp【i】【j】 For the first time i A classroom , The location of the previous candy store is j, What is the minimum cost of .
There are two kinds , One is to build a candy store here .dp【i】【i】=min(dp【i】【i】,dp【i-1】【j】+v【i】)(1<=j<i).
Second, do not build candy stores .dp【i】【j】=min(dp【i】【j】,dp【i-1】【j】+d【i】-d【j】)(1<=j<i).
Of course , The first classroom must build a candy store dp[1][1]=a[1].n.
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int const N=1e5+10;
typedef long long ll;
struct node{
ll m,n;
}a[3010];
ll dp[3010][3010];
ll const inf=1e9+10;
int cmp(node x,node y)
{
return x.m<y.m;
}
int main()
{
int nn;
while(~scanf("%d",&nn))
{
for(int i=1;i<=nn;i++)
{
scanf("%lld%lld",&a[i].m,&a[i].n);
}
sort(a+1,a+nn+1,cmp);
memset(dp,inf,sizeof(dp));
dp[1][1]=a[1].n;
for(int i=1;i<=nn;i++)
for(int j=1;j<i;j++)
{
dp[i][j]=min(dp[i][j],dp[i-1][j]+a[i].m-a[j].m);
dp[i][i]=min(dp[i][i],dp[i-1][j]+a[i].n);
}
ll sum=inf;
for(int i=1;i<=nn;i++)
sum=min(sum,dp[nn][i]);
printf("%lld\n",sum);
}
return 0;
}
边栏推荐
- [exercise-3] (UVA 442) matrix chain multiplication
- 程序员的你,有哪些炫技的代码写法?
- 信息安全-威胁检测-flink广播流BroadcastState双流合并应用在过滤安全日志
- Nodejs+vue网上鲜花店销售信息系统express+mysql
- frida hook so层、protobuf 数据解析
- Auto.js入门
- Opencv learning log 32 edge extraction
- China chart recorder market trend report, technology dynamic innovation and market forecast
- Shell Scripting
- 【练习-10】 Unread Messages(未读消息)
猜你喜欢
Information security - threat detection - detailed design of NAT log access threat detection platform
Penetration test (4) -- detailed explanation of meterpreter command
Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B
Penetration test (1) -- necessary tools, navigation
渗透测试 ( 1 ) --- 必备 工具、导航
[exercise-5] (UVA 839) not so mobile (balance)
Gartner:关于零信任网络访问最佳实践的五个建议
渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具
b站 实时弹幕和历史弹幕 Protobuf 格式解析
【高老师软件需求分析】20级云班课习题答案合集
随机推荐
Information security - Analysis of security orchestration automation and response (soar) technology
Accounting regulations and professional ethics [1]
SSM框架常用配置文件
Research Report on market supply and demand and strategy of Chinese graphic screen printing equipment industry
入门C语言基础问答
[teacher Gao UML software modeling foundation] collection of exercises and answers for level 20 cloud class
【练习-11】4 Values whose Sum is 0(和为0的4个值)
树莓派CSI/USB摄像头使用mjpg实现网页摄像头监控
China potato slicer market trend report, technical dynamic innovation and market forecast
Opencv learning log 12 binarization of Otsu method
Opencv learning log 31 -- background difference
数据在内存中的存储&载入内存,让程序运行起来
Cost accounting [24]
Alice and Bob (2021牛客暑期多校训练营1)
Accounting regulations and professional ethics [5]
[exercise-2] (UVA 712) s-trees
frida hook so层、protobuf 数据解析
1010 things that college students majoring in it must do before graduation
Record of brushing questions with force deduction -- complete knapsack problem (I)
【练习-2】(Uva 712) S-Trees (S树)