Cleaning Shifts
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 3563   Accepted: 1205

Description

Farmer John's cows, pampered since birth, have reached new heights of fastidiousness. They now require their barn to be immaculate. Farmer John, the most obliging of farmers, has no choice but hire some of the cows to clean the barn.

Farmer John has N (1 <= N <= 10,000) cows who are willing to do some cleaning. Because dust falls continuously, the cows require that the farm be continuously cleaned during the workday, which runs from second number M to second number E during the day (0 <= M <= E <= 86,399). Note that the total number of seconds during which cleaning is to take place is E-M+1. During any given second M..E, at least one cow must be cleaning.

Each cow has submitted a job application indicating her willingness to work during a certain interval T1..T2 (where M <= T1 <= T2 <= E) for a certain salary of S (where 0 <= S <= 500,000). Note that a cow who indicated the interval 10..20 would work for 11 seconds, not 10. Farmer John must either accept or reject each individual application; he may NOT ask a cow to work only a fraction of the time it indicated and receive a corresponding fraction of the salary.

Find a schedule in which every second of the workday is covered by at least one cow and which minimizes the total salary that goes to the cows.

Input

Line 1: Three space-separated integers: N, M, and E.

Lines 2..N+1: Line i+1 describes cow i's schedule with three space-separated integers: T1, T2, and S.

Output

Line 1: a single integer that is either the minimum total salary to get the barn cleaned or else -1 if it is impossible to clean the barn.

Sample Input

3 0 4
0 2 3
3 4 2
0 0 1

Sample Output

5

Hint

Explanation of the sample:

FJ has three cows, and the barn needs to be cleaned from second 0 to second 4. The first cow is willing to work during seconds 0, 1, and 2 for a total salary of 3, etc.

Farmer John can hire the first two cows.

Source

题意:
要处理m~e时间段的东西,有n个人,每个人能处理l~r连续时间段的东西并且费用为w,问将这m~e时间段的东西都处理完的最小花费。
输入n,m,e;
输入n行l,r,w;
输出最小花费
代码:
//容易想到dp但是没想到可以用线段树处理区间最小值,dp[i]表示到达时间i
//时的最小花费,将区间按照右值从小到大排序,然后枚举区间右值,
//dp[r]=min(dp[r],min(dp[l-1~r-1])+w),其中后一项用线段树处理区间最小值。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=;
const int maxm=;
int n,m,e,minv[maxm*],f[maxm];
struct Lu{
int l,r,w;
Lu(){}
Lu(int a,int b,int c):l(a),r(b),w(c){}
bool operator < (const Lu &p)const{
return r<p.r;
}
}L[maxn];
void pushup(int rt){
minv[rt]=min(minv[rt<<],minv[rt<<|]);
}
void build(int l,int r,int rt){
minv[rt]=inf;
if(l==r) return;
int mid=(l+r)>>;
build(l,mid,rt<<);
build(mid+,r,rt<<|);
pushup(rt);
}
void update(int id,int v,int l,int r,int rt){
if(l==r){
minv[rt]=v;
return;
}
int mid=(l+r)>>;
if(id<=mid) update(id,v,l,mid,rt<<);
else update(id,v,mid+,r,rt<<|);
pushup(rt);
}
int query(int ql,int qr,int l,int r,int rt){
if(ql<=l&&qr>=r)
return minv[rt];
int mid=(l+r)>>,ans=inf;
if(ql<=mid) ans=min(ans,query(ql,qr,l,mid,rt<<));
if(qr>mid) ans=min(ans,query(ql,qr,mid+,r,rt<<|));
return ans;
}
int main()
{
while(scanf("%d%d%d",&n,&m,&e)==){
e-=m; //将区间左移到从0开始
int cnt=;
for(int i=;i<n;i++){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
if(y<m||x>e) continue; //去掉不可行的区间
x-=m;y-=m;
if(x<) x=;
if(y>e) y=e;
L[cnt++]=Lu(x,y,z);
}
sort(L,L+cnt);
memset(f,inf,sizeof(f));
build(,e,);
for(int i=;i<n;i++){
int tmp=inf;
if(L[i].l==) tmp=L[i].w;
else tmp=query(L[i].l-,L[i].r-,,e,)+L[i].w;
f[L[i].r]=min(f[L[i].r],tmp);
if(f[L[i].r]<inf)
update(L[i].r,f[L[i].r],,e,);
}
if(f[e]>=inf) f[e]=-;
printf("%d\n",f[e]);
}
return ;
}
 

POJ 3171 DP的更多相关文章

  1. POJ 3171 Cleaning Shifts(DP+zkw线段树)

    [题目链接] http://poj.org/problem?id=3171 [题目大意] 给出一些区间和他们的价值,求覆盖一整条线段的最小代价 [题解] 我们发现对区间右端点排序后有dp[r]=min ...

  2. POJ 3171.Cleaning Shifts-区间覆盖最小花费-dp+线段树优化(单点更新、区间查询最值)

    Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4721   Accepted: 1593 D ...

  3. POJ 3171 区间最小花费覆盖 (DP+线段树

    Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4245   Accepted: 1429 D ...

  4. POJ 3171 区间覆盖最小值&&线段树优化dp

    Cleaning Shifts Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4715   Accepted: 1590 D ...

  5. hdu 1513 && 1159 poj Palindrome (dp, 滚动数组, LCS)

    题目 以前做过的一道题, 今天又加了一种方法 整理了一下..... 题意:给出一个字符串,问要将这个字符串变成回文串要添加最少几个字符. 方法一: 将该字符串与其反转求一次LCS,然后所求就是n减去 ...

  6. poj 1080 dp如同LCS问题

    题目链接:http://poj.org/problem?id=1080 #include<cstdio> #include<cstring> #include<algor ...

  7. poj 1609 dp

    题目链接:http://poj.org/problem?id=1609 #include <cstdio> #include <cstring> #include <io ...

  8. POJ 1037 DP

    题目链接: http://poj.org/problem?id=1037 分析: 很有分量的一道DP题!!! (参考于:http://blog.csdn.net/sj13051180/article/ ...

  9. Jury Compromise POJ - 1015 dp (标答有误)背包思想

    题意:从 n个人里面找到m个人  每个人有两个值  d   p     满足在abs(sum(d)-sum(p)) 最小的前提下sum(d)+sum(p)最大 思路:dp[i][j]  i个人中  和 ...

随机推荐

  1. 直线石子合并(区间DP)

    石子合并 时间限制:1000 ms  |  内存限制:65535 KB 描述有N堆石子排成一排,每堆石子有一定的数量.现要将N堆石子并成为一堆.合并的过程只能每次将相邻的两堆石子堆成一堆,每次合并花费 ...

  2. [redis] linux下哨兵篇(3)

    一.前言1.为何部署sentinel哨兵前文redis主从架构中,当主服务故障时,需要手动将从服务切换为主服务,sentinel服务就是将这个过程自动化.主要功能有:1)不时监控主从服务正常运行2)可 ...

  3. Scrum立会报告+燃尽图(十一月二十日总第二十八次):功能开发与纪录版本控制报告

    此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2284 项目地址:https://git.coding.net/zhang ...

  4. Alpha发布——视频博客

    1.视频链接 视频上传至优酷自频道,地址链接:https://v.youku.com/v_show/id_XMzg5MzQ4MzM2MA==.html?spm=a2h0k.11417342.sores ...

  5. 软工1816 · Alpha冲刺(9/10)

    团队信息 队名:爸爸饿了 组长博客:here 作业博客:here 组员情况 组员1(组长):王彬 过去两天完成了哪些任务 学习jQuery的AJAX部分的基础知识,对web端如何异步获取服务器信息有了 ...

  6. DL开源框架Caffe | 模型微调 (finetune)的场景、问题、技巧以及解决方案

    转自:http://blog.csdn.net/u010402786/article/details/70141261 前言 什么是模型的微调?   使用别人训练好的网络模型进行训练,前提是必须和别人 ...

  7. Tomcat配置 —— server.xml

    Tomcat的核心组件是servlet容器. Tomcat各个组件之间的嵌套关系 server.xml配置如下: <Server port="8005" shutdown=& ...

  8. MDL数据结构

    微软的文档里对MDL的描述感觉语焉不详,这两天在找工作的间隙逆向+黑盒测试了一下MmBuildMdlForNonPagedPool,把得到的一些理解描述下来. 一.MDL数据结构 MDL是用来建立一块 ...

  9. workstation vmware 制作vm模板

    [root@VM166136 ~]# cat copy_vmware.sh #!/bin/bash if [ $(id -u) -ne 0 ];then echo "Please use t ...

  10. javascript之彻底理解this

    彻底理解this,需要彻底理解函数 函数是复杂类型,存储在堆中.  函数是独立的, 对象中的方法只是对象中有个函数的引用 函数被调用时,调用者会像被调用者提供个上下文环境, 这个环境就是this 构造 ...