Codeforces 1106E. Lunar New Year and Red Envelopes(DP)
E. Lunar New Year and Red Envelopes
题意:
在长度为n的时间轴上,有k个红包,每个红包有领取时间段[s,t],价值w,以及领了个这个红包之后,在时间d到来之前无法再进行领取操作。每次领取的策略是取当前可领取红包中w最大的,w相同时取d最大的。再给m个干扰机会,一个干扰机会可以使其在任意一个x这个时间点无法进行领取操作直到x+1。问最优使用不超过m次干扰下,将领取的最小红包价值总和。(n,k<=1e5,m<=200)
思路:
这场因为评测机出问题,UR了。前四题没什么价值,这题DP的感觉出的挺好。
虽然状态的定义和转移没什么难度(dp[i][j]从i到n使用j次干扰的最小领取红包价值,这样定义方便倒着推,倒着推则是由于红包的d属性的存在),但是处理每个时间点应该领取哪个红包的实现方式挺巧妙的,用两个vector数组分别记录每个时间点有哪些红包出现和消失,再用set动态维护当前应领取的红包。
代码:
#include<bits/stdc++.h>
#define dd(x) cout<<#x<<" = "<<x<<" "
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define sz(x) int(x.size())
#define All(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef priority_queue<P> BQ;
typedef priority_queue<int,vector<int>,greater<int> > SQ;
const int maxn=1e5+10,mod=1e9+7,INF=0x3f3f3f3f;
vector<pair<P,int> > S[maxn],T[maxn];
multiset<pair<P,int> > st;
ll dp[maxn][205];
int main()
{
int n,m,k;
cin>>n>>m>>k;
for (int i=1;i<=k;++i)
{
int s,t,d,w;
scanf("%d%d%d%d",&s,&t,&d,&w);
S[s-1].pb(mp(mp(w,d),i)),T[t].pb(mp(mp(w,d),i));
}
memset(dp,INF,sizeof(dp));
dp[n+1][0]=0;
for (int i=n;i;--i)
{
for (auto& j:T[i])
st.insert(j);
for (auto& j:S[i])
st.erase(j);
if (st.empty())
for (int j=0;j<=m;++j)
dp[i][j]=dp[i+1][j];
else
{
int w=st.rbegin()->fi.fi,d=st.rbegin()->fi.se;
for (int j=0;j<=m;++j)
dp[i][j]=dp[d+1][j]+w;
for (int j=1;j<=m;++j)
dp[i][j]=min(dp[i][j],dp[i+1][j-1]);
}
}
cout<<*min_element(dp[1],dp[1]+m+1);
return 0;
}
Codeforces 1106E. 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 Round #369 (Div. 2) C. Coloring Trees(dp)
Coloring Trees Problem Description: ZS the Coder and Chris the Baboon has arrived at Udayland! They ...
- Codeforces Round #367 (Div. 2) C. Hard problem(DP)
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...
- Codeforces Round #245 (Div. 1) B. Working out (dp)
题目:http://codeforces.com/problemset/problem/429/B 第一个人初始位置在(1,1),他必须走到(n,m)只能往下或者往右 第二个人初始位置在(n,1),他 ...
- Codeforces Round #260 (Div. 1) 455 A. Boredom (DP)
题目链接:http://codeforces.com/problemset/problem/455/A A. Boredom time limit per test 1 second memory l ...
- Codeforces Round #349 (Div. 2) C. Reberland Linguistics (DP)
C. Reberland Linguistics time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Round #369 (Div. 2) C. Coloring Trees (DP)
C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #552 (Div. 3) F. Shovels Shop(dp)
题目链接 大意:给你n个物品和m种优惠方式,让你买k种,问最少多少钱. 思路:考虑dpdpdp,dp[x]dp[x]dp[x]表示买xxx种物品的最少花费,然后遍历mmm种优惠方式就行转移就好了. # ...
- 【Codeforces】CF 9 D How many trees?(dp)
题目 传送门:QWQ 分析 用$ dp[i][j] $表示用i个节点,有多少深度小于等于j的二叉树. 答案是$ dp[n][n] - dp[n][h-1] $ 转移时枚举左子树的节点数量,就可以知道右 ...
随机推荐
- RabbitMQ安装&简单使用
.什么是RabbitMQ.详见 http://www.rabbitmq.com/. 作用就是提高系统的并发性,将一些不需要及时响应客户端且占用较多资源的操作,放入队列,再由另外一个线程,去异步处理这些 ...
- Python字符串常用的方法——真心觉得比java,c好用
# Strings have many methods wo can use rand_string=" life is a beautiful struggle " print( ...
- Java写学生管理系统
package Homework08;/*调试了一上午,收获:学会了昨天的debug的使用吸取教训:Student stus[]=new Student[2]; for (int i=0;i<s ...
- QQ浏览器、搜狗浏览器等兼容模式下,Asp.NetCore下,Cookie、Session失效问题
原文:QQ浏览器.搜狗浏览器等兼容模式下,Asp.NetCore下,Cookie.Session失效问题 这些狗日的浏览器在兼容模式下,保存Cookie会失败,是因为SameSiteMode默认为La ...
- 如何演讲-摘录自TED
一.首先,只传递一个主要思想 想法是个很复杂的东西,你要对你的内容做减法,突出重点,只关注一个主要思想,也就是你最富有热情的观点,利用机会好好的阐述它.你要给出案例,分享案例,生动阐述所以,找到一个 ...
- CentOS7利用systemctl添加dotnet后台服务
/usr/lib/systemd/system/zl.service systemctl enable zl.service systemctl start zl.service [Unit]Desc ...
- pm2 常用操作
PM2全局安装 npm i pm2 -g PM2启动.net core pm2 start "dotnet xxx.dll" --name api //name后面跟你要取的名字 ...
- HTML的标签简单概括
段落标签 <p></p> 属性 说明 值 align 对其方式 left(默认).right.center 水平线 <hr /> 属性 说明 值 width ...
- kalilinux 渗透测试笔记
声明:本文理论大部分是苑房弘kalilinux渗透测试的内容 第五章:基本工具 克隆网页,把gitbook的书记下载到本地 httrack "http://www.mybatis.org/m ...
- Makefile中代码写在同一行和分开几行写有什么区别?
在Makefile中,写在同一行的代码就相当于是在Linux中的同一行命令行写的代码一样,是一次性执行的:如程序中如下编写Makefile代码(请注意,两个命令之间应该使用分号“:”来进行分隔): a ...