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 ...
随机推荐
- PID算法通俗理解,平衡车,倒立摆,适合不理解PID算法的人来看!
先插句广告,本人QQ522414928,不熟悉PID算法的可以一起交流学习,随时在线(PID资料再我的另一篇博客里) 倒立摆资料连接↓ https://www.cnblogs.com/LiuXinyu ...
- 【原创】NES第一波:如何用通用型6502宏汇编器,制用NES/FC游戏。
在163的博客关了呀.在这边重新开张了. 以后若网友有什么要长篇解答的问题,也在这儿作答. 作为第一波原创文章,我打算做一次小白示范.那就是一步一步的展示某个汇编编译器的用法. 一.科普 很多人认为程 ...
- 有容云:上车 | 听老司机谈Docker安全合规建设
编者注: 本文根据7月19日DockOne社群分享内容整理而成,分享嘉宾蒋运龙,有容云高级咨询顾问,一个IT的老兵,十年来混迹于存储.三网融合.多屏互动.智能穿戴.第三方支付.Docker等行业:经历 ...
- Linux基础文件打包
一.打包与解压 (一).打包压缩 [root@linux ~]# tar -czf etc1.tar.gz /etc //-z 调用gzip [root@linux ~]# tar -cjf etc2 ...
- SpringMVC学习笔记之---简单入门
SpringMVC简单入门 (一)什么是MVC设计模式 (1)model:模型数据,业务逻辑 (3)view:呈现模型,与用户进行交互 (3)controller:负责接收并处理请求,响应客户端 (二 ...
- BootStrap实现简单响应式导航菜单
用BootStrap实现响应式导航栏,我会对其中的一些样式进行说明. 先上代码,是一个很简单的Demo. <!doctype html> <html> <head&g ...
- MATLAB使用过程中遇到的问题(持续更新)
note:如果对你有帮助,请点赞评论哟!!! 问题1:每次双击.m文件都会自动打开一个matlab程序 step1:下载这个文件 http://pan.baidu.com/s/1pL2ULOf ste ...
- python3学习--文件读写
这一篇我们来看文件读写操作. 打开和创建文件主要是open()函数: f = open('filename','r') # 读模式 f = open('filename','w') # 写模式 f = ...
- Vue系列:Vue Router 路由梳理
Vue Router 是 Vue.js 官方的路由管理器.它和 Vue.js 的核心深度集成,让构建单页面应用变得易如反掌.包含的功能有: 嵌套的路由/视图表 模块化的.基于组件的路由配置 路由参数. ...
- soap天气查询
public class MainActivity extends AppCompatActivity { private TextView tvContent; @Override protecte ...