hdu6024 Building Shops(区间dp)
https://cn.vjudge.net/problem/HDU-6024
分开考虑某一点种与不种,最后取二者的最小值。
dp[i][1] = min(dp[i-1][0], dp[i-1][1])+c[i];
dp[i][0]则是j从i-1~1递减,判断当j种是,i的最小值,然后取总的最小。
注意dp初始化为INF,以及要开long long
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define INF 1e9
typedef long long ll;
using namespace std;
int n, m;
ll dp[][];
typedef struct {
ll x, c;
}Node;
Node node[];
bool cmp(const Node a, const Node b)
{
return a.x<b.x;
}
int main()
{
while(cin >> n){
for(int i = ; i <= n; i++){
cin >> node[i].x >> node[i].c;
}
for(int i = ; i <= n; i++){
dp[i][] = INF;
dp[i][] = INF;
}
dp[][]=;dp[][]=;
sort(node+, node+n+, cmp);
for(int i = ; i <= n; i++){
dp[i][] = min(dp[i-][], dp[i-][])+node[i].c;
ll tmp = ;
for(int j = i-; j >= ; j--){
tmp += (i-j)*(node[j+].x - node[j].x);//次数*长度
dp[i][] = min(dp[i][], dp[j][]+tmp);
}
}
cout << min(dp[n][], dp[n][]) << endl;
}
return ;
}
hdu6024 Building Shops(区间dp)的更多相关文章
- HDU6024 Building Shops 2017-05-07 18:33 30人阅读 评论(0) 收藏
Building Shops Time Limit: 2000/1000 MS ...
- HDU6024:Building Shops(DP)
传送门 题意 在一条直线上有n个教室,现在要设置糖果店,使得最后成本最小,满足以下两个条件: 1.若该点为糖果店,费用为cost[i]; 2.若不是,则为loc[i]-最近的糖果店的loc 分析 dp ...
- HDU6024:Building Shops(简单DP)
Building Shops Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- HDU5900 QSC and Master(区间DP + 最小费用最大流)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5900 Description Every school has some legends, ...
- 2016 年沈阳网络赛---QSC and Master(区间DP)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5900 Problem Description Every school has some legend ...
- UVALive 4987---Evacuation Plan(区间DP)
题目链接 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- 2016 ACM/ICPC Asia Regional Shenyang Online 1009/HDU 5900 区间dp
QSC and Master Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 【BZOJ-4380】Myjnie 区间DP
4380: [POI2015]Myjnie Time Limit: 40 Sec Memory Limit: 256 MBSec Special JudgeSubmit: 162 Solved: ...
- 【POJ-1390】Blocks 区间DP
Blocks Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5252 Accepted: 2165 Descriptio ...
随机推荐
- Nodejs通过账号密码连接MongoDB数据库
转自https://blog.csdn.net/szu_lzz/article/details/77435804#commentBox 1.创建管理员 首先开启Mongo服务,然后切换admin数据库 ...
- noip飞扬的小鸟
题解: 挺简单的题目 f[i][j]表示x坐标为i,y坐标为j的最小值 会发现那个东西是个完全背包 从f[i][j-a[i]]转移一下就是O(1)转移的了 另外上界为m这个要特判一下 我把sum[a[ ...
- yum安装的时候报错,关于python的函数库
我在执行yum -y install nc命令的时候出现如下报错 There was a problem importing one of the Python modulesrequired to ...
- Codeforces 229E Gifts 概率dp (看题解)
Gifts 感觉题解写的就是坨不知道什么东西.. 看得这个题解. #include<bits/stdc++.h> #define LL long long #define LD long ...
- 51Nod1038 X^A Mod P 数论 原根 BSGS
原文链接https://www.cnblogs.com/zhouzhendong/p/51Nod1038.html 题目传送门 - 51Nod1038 题意 题解 在模质数意义下,求高次剩余,模板题. ...
- HDU5117 Fluorescent 期望 计数 状压dp 动态规划
原文链接https://www.cnblogs.com/zhouzhendong/p/HDU5117.html 题目传送门 - HDU5117 题意 $T$ 组数据. 给你 $n$ 盏灯 ,$m$ 个 ...
- Linux安装Tomcat-Nginx-FastDFS-Redis-Solr-集群——【第二集之新建虚拟机】
1, 2, 3, 4,(如果选择版本时,发现选项中没有centos,可以选择other linux2.6.x kernel) 5,(虚拟机命名:Centos_用途_IP) 6,(选择Split vir ...
- day 36 网络编程终结内容
今日概要: 1 gevent模块 协程:单线程下实现并发(并发指的是看起来同时运行,实现方式:切换+保存状态) 遇到IO切换到其他任务去执行,这种切换才能提高效率 gevent模块 1.切换+保存状态 ...
- 怎样将一个Long类型的数据转换成字节数组
直接上代码: //先写进去 long n = 1000000L; ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutpu ...
- ASP.NET 页面执行顺序
1.对象初始化(Onlnit方法) 页面中的控件(包括页面本身)都是在它们最初的form中被首次初始化的,通过在aspx页面的后台代码文件的构造器中声明你的对象,页面将知道对象的类型,并知道需要创建多 ...