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 ...
随机推荐
- Leetcode5078. 负二进制数相加
问题: 5078. 负二进制数相加 给出基数为 -2 的两个数 arr1 和 arr2,返回两数相加的结果. 数字以 数组形式 给出:数组由若干 0 和 1 组成,按最高有效位到最低有效位的顺序排列. ...
- nginx url rewrite break和last的区别
break 将重写的URI作为一个新的URI,在本块中继续处理,将重写后 的地址在当前location块中处理,不会将新的URI转向到其他location块中 last,终止继续在本location块 ...
- vue 顶级组件
快 有时候懒的把一些通用组件写到template里面去,而业务中又需要用到,比如表示loading状态这样组件. 如果是这样的组件,可以选择把组件手动初始化,让组件在整个app生命周期中始终保持活跃. ...
- 点击tr实现选择checkbox功能,点击checkobx的时候阻止冒泡事件, jquery给checkbox添加checked属性或去掉checked属性不能使checkobx改变状态
给tr添加点击事件,使用find方法查找tr下的所有层级的元素,children只查找下一层级的元素,所以使用find.find的返回值为jquery对象,在这个项目中不知道为什么使用jquery给c ...
- ccf 201712-2 游戏(Python实现)
一.原题 问题描述 试题编号: 201712-2 试题名称: 游戏 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 有n个小朋友围成一圈玩游戏,小朋友从1至n编号,2号小朋友坐 ...
- Yii2.0 的安装学习
视频学习地址: 后盾网视频: http://www.houdunren.com/houdunren18_lesson_76?vid=7350 与<Yii框架>不得不说的故事—基础篇 htt ...
- HDU - 5884 Sort (二分答案+贪心)
有n个数字,你需要把这n个数字合成一个数字,每次只能把k个数字合并成一个,花费为这k个数字的和. 给一个最大花费,问不超过这个最大花费的情况下,k的最小值. Sample Input 1 5 25 1 ...
- python for data analysis chapter1~2
Q1:numpy与series的区别:index Tab补全(任意路径Tab) 内省(函数:?显示文档字符串,??显示源代码:结合通配符:np.* load *?) %load .py ctrl-c( ...
- bzoj3262陌上花开 三维数点 cdq+树状数组
大早上的做了一道三维数点一道五位数点,神清气爽! 先给一维排序,变成一个奇怪的动态的二维数点(相当于有一个扫描面扫过去,导致一系列的加点和询问) 然后cdq分治,再变回静态,考虑前半段对后半段的影响 ...
- NuGet安装本地包命令行
尝试安装本地的NuGet包. 键入 "get-help NuGet" 可查看所有可用的 NuGet 命令. install-package Polly.Net40Async-Sig ...