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)的更多相关文章

  1. Codeforces 1106 E. Lunar New Year and Red Envelopes 优先队列+dp

    题意大致是Bob新年拿红包,每个红包可以在s-t时间内取,但是取了之后得在d+1时间开始才能继续取红包. 同时他女儿能在m个时间点阻止他取红包,求女儿阻止后Bob取得的w总和最小值. Bob取红包的策 ...

  2. 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 ...

  3. Codeforces Round #367 (Div. 2) C. Hard problem(DP)

    Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solvin ...

  4. Codeforces Round #245 (Div. 1) B. Working out (dp)

    题目:http://codeforces.com/problemset/problem/429/B 第一个人初始位置在(1,1),他必须走到(n,m)只能往下或者往右 第二个人初始位置在(n,1),他 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #552 (Div. 3) F. Shovels Shop(dp)

    题目链接 大意:给你n个物品和m种优惠方式,让你买k种,问最少多少钱. 思路:考虑dpdpdp,dp[x]dp[x]dp[x]表示买xxx种物品的最少花费,然后遍历mmm种优惠方式就行转移就好了. # ...

  9. 【Codeforces】CF 9 D How many trees?(dp)

    题目 传送门:QWQ 分析 用$ dp[i][j] $表示用i个节点,有多少深度小于等于j的二叉树. 答案是$ dp[n][n] - dp[n][h-1] $ 转移时枚举左子树的节点数量,就可以知道右 ...

随机推荐

  1. 教你如何进行移动端APP测试

    1.安全测试(权限) 1)软件权限:其中包括发送信息,拨打电话,链接网络,访问手机信息,联系人信息等等 2)数据在本地的存储.传输等 3)执行某些操作时导致的输入有效性验证.授权.数据加密等方面 4) ...

  2. 基于bootstrap selectpicker ,实现select下拉框模糊查询功能

    1.html代码块 需要引入bootstrap的css js jquery bootstrap.css bootstrap-select.min.css jquery-1.11.3.min.js bo ...

  3. hdu 6058 思维

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=6058 分析题目的时候,由于枚举的区间很多,而第k大的值范围小,应该要想到去枚举第k大的值然后找到这个值对答 ...

  4. django+uwsgi+nginx: websock 报502/400

    耽搁了近2个月,终于解决了,主要是nginx/uwsgi/django相关的配置: 一.django工程settings.py,添加 WEBSOCKET_FACTORY_CLASS = "d ...

  5. shiro 权限过滤器 -------(1)

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABBEAAAJRCAIAAACcEbhqAAAgAElEQVR4nO3dv67sVtkHYEefhIKUIC ...

  6. 获取impala下所有的数据库建表语句

    方法一: 现在的导出还是有缺陷的,导出的文件中还是存在其他不必要的信息 #!/bin/bash ##获取数据库 databases=$(hive -e "show databases; ex ...

  7. 第四章、Django之模型层---创建模型

    目录 第四章.Django之模型层---创建模型 一.写models.py 第四章.Django之模型层---创建模型 一.写models.py from django.db import model ...

  8. 十八,helm的原理及基础使用

    目录 helm介绍 核心术语 helm安装 helm安装 Tiller安装 创建tiller相关的rbac helm使用 添加chart源 helm常用命令: 基础命令 自定义chart 一.char ...

  9. LNMP安装与配置之Nginx

    Nginx简介 Nginx (engine x) 是一个高性能的HTTP和反向代理web服务器,同时也提供了IMAP/POP3/SMTP服务.Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Ramb ...

  10. 嵌入式Linux应用开发完全手册读书笔记——交叉编译工具选项说明

    交叉编译工具选项说明 arm-linux-gcc 一个c/c++文件要变成可执行文件需要4步:预处理 -> 编译 -> 汇编 -> 链接: 在使用arm-linux-gcc时的常用选 ...