CF - 1106 E Lunar New Year and Red Envelopes DP
题解:
首先要处理出每个时间点会选择哪一个线段。
对于这个问题,可以用multiset去维护信息。
当时间线开始的时候,往mutiset里面插入这个信息,当时间线结束的时候,删除这个信息。
每次只要取出最大位就好了。
然后,就是状态转移,注意的就是只有转移进来过的状态才能转移出去。
代码:
/*
code by: zstu wxk
time: 2019/02/03
*/
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
int n, m, k;
struct Node{
int d, w;
bool operator < (const Node & x) const{
if(w == x.w) return d > x.d;
return w > x.w;
}
};
vector<Node> in[N], out[N];
LL dp[N][];
multiset<Node> st;
void Ac(){
for(int i = ; i <= k; ++i){
int s, t, d, w;
scanf("%d%d%d%d", &s, &t, &d, &w);
in[s].pb({d,w});
out[t].pb({d,w});
}
memset(dp, INF, sizeof dp);
dp[][] = ;
for(int i = ; i <= n; ++i){
for(Node & x : in[i]){
st.insert(x);
for(int j = ; j <= m; ++j){
if(dp[i][j] == INF) continue;
dp[i+][j+] = min(dp[i+][j+], dp[i][j]);
if(st.empty())
dp[i+][j] = min(dp[i+][j], dp[i][j]);
else {
Node x = *st.begin();
dp[x.d+][j] = min(dp[x.d+][j], dp[i][j]+x.w);
}
}
for(Node &x : out[i])
st.erase(st.lower_bound(x));
}
LL ans = INF;
for(int j = ; j <= m; ++j) ans = min(ans, dp[n+][j]);
printf("%I64d\n", ans);
}
int main(){
while(~scanf("%d%d%d", &n, &m, &k)){
Ac();
}
return ;
}
CF - 1106 E Lunar New Year and Red Envelopes DP的更多相关文章
- Codeforces 1106 E. Lunar New Year and Red Envelopes 优先队列+dp
题意大致是Bob新年拿红包,每个红包可以在s-t时间内取,但是取了之后得在d+1时间开始才能继续取红包. 同时他女儿能在m个时间点阻止他取红包,求女儿阻止后Bob取得的w总和最小值. Bob取红包的策 ...
- Codeforces #536 div2 E (1106E)Lunar New Year and Red Envelopes (DP)
题意:过年了,Bob要抢红包.抢红包的时间段为1 - n,有m个红包,每个红包有三个属性:st(红包出现的时间), ed(红包消失的时间),d(如果抢了这个红包,能够抢下一个红包的时间),w(红包的收 ...
- Codeforces 1106E. Lunar New Year and Red Envelopes(DP)
E. Lunar New Year and Red Envelopes 题意: 在长度为n的时间轴上,有k个红包,每个红包有领取时间段[s,t],价值w,以及领了个这个红包之后,在时间d到来之前无法再 ...
- 【Codeforces 1106E】 Lunar New Year and Red Envelopes
Codeforces 1106 E 题意:有\(k\)个红包,第\(i\)个红包可以在\(s_i\)到\(t_i\)的时间内抢,同时获得\(w_i\)的钱,但是抢完以后一直到\(d_i\)都不可以继续 ...
- CF1106E Lunar New Year and Red Envelopes
比赛时看到这题懵逼了,比完赛仔细一想是个很简单的dp = = 由于题目限制,可以发现\(B\)取红包的策略是唯一的,可以用优先队列预处理出\(B\)在第\(i\)秒可以拿到的红包的收益\(w_i\)和 ...
- Lunar New Year and Red Envelopes CodeForces - 1106E (dp)
大意: 总共$n$的时间, $k$个红包, 红包$i$只能在时间$[s_i,t_i]$范围内拿, 并且拿完后时间跳到$d_i+1$,Bob采用贪心策略,每个时间点若有红包能取则取钱数$w_i$最大的, ...
- 【Codeforces 1106E】Lunar New Year and Red Envelopes
[链接] 我是链接,点我呀:) [题意] 给你k个红包,每个红包可以在si..ti的时间范围内拿走. 抢完红包之后你得到wi元,然后你需要在di+1时刻才能继续抢红包 时间是线性的从1..n 然后某个 ...
- Codeforces Round #536 E. Lunar New Year and Red Envelopes /// 贪心 记忆化搜索 multiset取最大项
题目大意: 给定n m k:(1≤n≤1e5, 0≤m≤200, 1≤k≤1e5) 表示n个时间长度内 最多被打扰m次 k个红包 接下来k行描述红包 s t d w:(1≤s≤t≤d≤n , 1≤w≤ ...
- CF F. Shovels Shop(前缀和预处理+贪心+dp)
F. Shovels Shop time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
随机推荐
- 常用GDB命令行调试命令
po po是print-object的简写,可用来打印所有NSObject对象.使用举例如下: (gdb) po self <LauncherViewController: 0x552c570& ...
- C++单继承、多继承情况下的虚函数表分析
C++的三大特性之一的多态是基于虚函数实现的,而大部分编译器是采用虚函数表来实现虚函数,虚函数表(VTAB)存在于可执行文件的只读数据段中,指向VTAB的虚表指针(VPTR)是包含在类的每一个实例当中 ...
- oracle的开窗函数
原创 select * from (select province, commodity, sum(price), ROW_NUMBER() OVER(PARTITION BY province o ...
- 『开发技术』Windows极简安装使用face_recognition
face_recognition是一个强大.简单.易上手的人脸识别开源项目,并且配备了完整的开发文档和应用案例,特别是兼容树莓派系统.此项目是世界上最简洁的人脸识别库,你可以使用Python和命令行工 ...
- bat 下 字符串拆分 类似 split 可以使用 for /f delims
@echo offset strin=AA,BB,CC,DDfor /f "tokens=1,2,3,4 delims=, " %%a in ('echo %strin%') do ...
- 监控JVM
WAS配置visualVM 在was控制台:找到应用程序服务器--java和进程管理--进程定义--JAVA虚拟机/通用JVM 参数 ,对应英文Application servers > ser ...
- Unity经典案例之:Fire Balls 多个圆环以及圆环的变速变向
版权申明: 本文原创首发于以下网站: 博客园『优梦创客』的空间:https://www.cnblogs.com/raymondking123 优梦创客的官方博客:https://91make.top ...
- git 技术栈
之前用的都是svn ,git还是要了解的,万一哪天要用了呢
- C++的精度控制
#include <iostream> #include <iomanip> using namespace std; int main( void ) { const dou ...
- python 32 操作系统与进程
目录 1. 操作系统 1.1 作用 1.2 操作系统的发展 2. 进程的理论 2.1 相关名词 2.2 进程的创建 2.3 进程的状态: 1. 操作系统 管理.控制.协调计算机硬件与软件资源的计算 ...