POJ 3171 区间覆盖最小值&&线段树优化dp
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 4715 | Accepted: 1590 |
Description
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
Lines 2..N+1: Line i+1 describes cow i's schedule with three space-separated integers: T1, T2, and S.
Output
Sample Input
3 0 4
0 2 3
3 4 2
0 0 1
Sample Output
5
Hint
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.
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a))
#define huan printf("\n")
#define debug(a,b) cout<<a<<" "<<b<<" "<<endl
#define ffread(a) fastIO::read(a)
using namespace std;
typedef long long ll;
const int maxn = 1e5+;
const ll inf = 1e12;
const ll mod = ;
const double epx = 1e-;
const double pi = acos(-1.0);
//head-----------------------------------------------------------------
ll minn[maxn*];
void PushUp(int rt)
{
minn[rt]=min(minn[rt<<],minn[rt<<|]);
}
void update(int x,ll val,int l,int r,int rt)
{
if(l==x&&r==x)
{
minn[rt]=val;
return;
}
int mid=(l+r)>>;
if(x<=mid)
update(x,val,l,mid,rt<<);
else
update(x,val,mid+,r,rt<<|);
PushUp(rt);
}
ll query(int L,int R,int l,int r,int rt)
{
if(L<=l&&R>=r)
{
return minn[rt];
}
int mid=(l+r)>>;
ll ans=1e12;
if(L<=mid) ans=min(ans,query(L,R,l,mid,rt<<));
if(R>mid) ans=min(ans,query(L,R,mid+,r,rt<<|));
return ans;
}
struct node
{
ll l,r,val;
}qujian[maxn];
bool cmp(node a,node b)
{
return a.r<b.r;
}
int main()
{
ll n,m,e;
scanf("%lld%lld%lld",&n,&m,&e);
m+=,e+=;
for(int i=;i<n;i++)
{
scanf("%lld%lld%lld",&qujian[i].l,&qujian[i].r,&qujian[i].val);
qujian[i].l+=,qujian[i].r+=;
}
sort(qujian,qujian+n,cmp);
for(int i=;i<=1e5;i++)
update(i,inf,,1e5,);
update(m-,,,1e5,);
for(int i=;i<n;i++)
{
if(qujian[i].r>=m)
{
ll tempmin=query(qujian[i].l-,qujian[i].r,,1e5,);
if(tempmin==inf)
continue;
ll temp=tempmin+qujian[i].val;
ll before=query(qujian[i].r,qujian[i].r,,1e5,);
if(before>temp)
update(qujian[i].r,temp,,1e5,);
}
}
ll ans=query(e,1e5,,1e5,);
if(ans==inf)
printf("-1\n");
else
printf("%lld\n",ans);
}
POJ 3171 区间覆盖最小值&&线段树优化dp的更多相关文章
- POJ 1769 Minimizing maximizer (线段树优化dp)
dp[i = 前i中sorter][j = 将min移动到j位置] = 最短的sorter序列. 对于sorteri只会更新它右边端点r的位置,因此可以把数组改成一维的,dp[r] = min(dp[ ...
- POJ 2376 Cleaning Shifts (线段树优化DP)
题目大意:给你很多条线段,开头结尾是$[l,r]$,让你覆盖整个区间$[1,T]$,求最少的线段数 题目传送门 线段树优化$DP$裸题.. 先去掉所有能被其他线段包含的线段,这种线段一定不在最优解里 ...
- 洛谷$P2605\ [ZJOI2010]$基站选址 线段树优化$dp$
正解:线段树优化$dp$ 解题报告: 传送门$QwQ$ 难受阿,,,本来想做考试题的,我还造了个精妙无比的题面,然后今天讲$dp$的时候被讲到了$kk$ 先考虑暴力$dp$?就设$f_{i,j}$表示 ...
- 2021.12.08 P1848 [USACO12OPEN]Bookshelf G(线段树优化DP)
2021.12.08 P1848 [USACO12OPEN]Bookshelf G(线段树优化DP) https://www.luogu.com.cn/problem/P1848 题意: 当农夫约翰闲 ...
- [AGC011F] Train Service Planning [线段树优化dp+思维]
思路 模意义 这题真tm有意思 我上下楼梯了半天做出来的qwq 首先,考虑到每K分钟有一辆车,那么可以把所有的操作都放到模$K$意义下进行 这时,我们只需要考虑两边的两辆车就好了. 定义一些称呼: 上 ...
- 4.11 省选模拟赛 序列 二分 线段树优化dp set优化dp 缩点
容易想到二分. 看到第一个条件容易想到缩点. 第二个条件自然是分段 然后让总和最小 容易想到dp. 缩点为先:我是采用了取了一个前缀最小值数组 二分+并查集缩点 当然也是可以直接采用 其他的奇奇怪怪的 ...
- 【bzoj3939】[Usaco2015 Feb]Cow Hopscotch 动态开点线段树优化dp
题目描述 Just like humans enjoy playing the game of Hopscotch, Farmer John's cows have invented a varian ...
- D - The Bakery CodeForces - 834D 线段树优化dp···
D - The Bakery CodeForces - 834D 这个题目好难啊,我理解了好久,都没有怎么理解好, 这种线段树优化dp,感觉还是很难的. 直接说思路吧,说不清楚就看代码吧. 这个题目转 ...
- Codeforces 1603D - Artistic Partition(莫反+线段树优化 dp)
Codeforces 题面传送门 & 洛谷题面传送门 学 whk 时比较无聊开了道题做做发现是道神题( 介绍一种不太一样的做法,不观察出决策单调性也可以做. 首先一个很 trivial 的 o ...
随机推荐
- NodeJS基础入门-Event
大多数Node.js核心API都采用惯用的异步事件驱动架构,其中某些类型的对象(触发器)会周期性地触发命名事件来调用函数对象(监听器). 例如,net.Server对象会在每次有新连接时触发事件;fs ...
- RSA非对称加密算法实现过程
RSA非对称加密算法实现过程 非对称加密算法有很多,RSA算法就是其中比较出名的算法之一,下面是具体实现过程 <?php /** */ class Rsa { /** * private key ...
- 【Linux命令】nohup和&差异,查看进程和终止进程!
最近在开发dueros的技能,官方提供的PHPSDK中有多个实力,而运行实例的命令如下是 nohup php -S 0.0.0.0:8029 myindex.php & 从命令来看,肯定是在8 ...
- Lecture 3
surface models 1. The two main methods of creating surface models are interpolation and triangulatio ...
- Apache ant 配置
ANT_HOME C:\Program Files(D)\apache-ant-1.10.1Path %ANT_HOME%/binant -v
- webpack 环境搭建+实现热更新
让我们一起构建一个小的app 为了便于你更好的了解Webpack带来的好处,我们将会构建一个非常小的app并将资源文件打包.在这个教程中我推荐基于Node4或Node5和NPM3来进行开发,这样就避免 ...
- ICCID
ICCID:Integrate circuit card identity 集成电路卡识别码(固化在手机SIM卡中) ICCID为IC卡的唯一识别号码,共有20位数字+英文组成,其编码格式为:XXX ...
- 零基础自学用Python 3开发网络爬虫
原文出处: Jecvay Notes (@Jecvay) 由于本学期好多神都选了Cisco网络课, 而我这等弱渣没选, 去蹭了一节发现讲的内容虽然我不懂但是还是无爱. 我想既然都本科就出来工作还是按照 ...
- ubuntu14.04修改mysql默认编码
修改文件为/etc/mysql/my.cnf [client] default-character-set = utf8 (ps:client的设置没变) [mysqld] lower_case_ta ...
- BZOJ1189 [HNOI2007]紧急疏散evacuate 【二分 + 网络流】
题目 发生了火警,所有人员需要紧急疏散!假设每个房间是一个N M的矩形区域.每个格子如果是'.',那么表示这是一 块空地:如果是'X',那么表示这是一面墙,如果是'D',那么表示这是一扇门,人们可以从 ...