题目大意:

给定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≤1e9)

表示在 s 到 t 的时间内都可开始获得该红包

该红包在时间 d 时才能完成获得 红包内有w硬币

在同一时间段内只能获得一个红包 不能同时获得两个及以上

求在被打扰的情况下使获得的红包硬币最少 是多少

用in out标记各红包可被获得的区间

用multiset维护在某个时间点可获得的红包有哪些 (放入in内的 去掉out内的)

multiset内部按w排序 那么在某个时间点取出w最大的就是获得红包的贪心策略 .rbegin()可获得multiset/set内的最后一项

按时间点记忆化搜索一下 dp[ 时间点 ][ 被打扰次数 ]来记忆

以上存储信息要用pair<> 用结构体会MLE

#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define mem(i,j) memset(i,j,sizeof(i))
#define pb push_back
#define mp(i,j) make_pair(i,j)
#define fir first
#define sec second
#define P pair<LL,LL>
const int N=1e5+;
P best[N]; // best[i] 在i位置的最佳策略
LL n, m, k;
LL dp[N][];
// 记忆化 dp[i][j]在i位置被打扰了j次能获得的最少硬币
multiset <P> now;
// 维护当前位置所有能取的红包 pair默认按first排序
vector <P> in[N], out[N];
// in为从该位置开始可取的 out为从该位置开始不可取的 void init() {
mem(dp,-); now.clear();
for(int i=;i<=n+;i++)
in[i].clear(), out[i].clear();
}
LL DFS(int ind,int c) {
if(ind>n) return 0LL;
if(dp[ind][c]>=0LL) return dp[ind][c];
LL res=best[ind].fir+DFS(best[ind].sec+,c); // 取这个红包
if(c<m) res=min(res,DFS(ind+,c+)); // 被女儿阻止
return dp[ind][c]=res;
} int main()
{
while(~scanf("%d%d%d",&n,&m,&k)) {
init();
for(int i=;i<k;i++) {
LL l,r,d,w;
scanf("%I64d%I64d%I64d%I64d",&l,&r,&d,&w);
in[l].pb(mp(w,d));
out[r+].pb(mp(w,d));
}
for(int i=;i<=n+;i++) {
for(int j=;j<in[i].size();j++)
now.insert(in[i][j]); // 加入可取的
for(int j=;j<out[i].size();j++)
now.erase(now.find(out[i][j])); // 去掉不可取的
if(now.size()) best[i]=*now.rbegin(); // 最佳策略是w最大的
else best[i]={0LL,(LL)i};
}
printf("%I64d\n",DFS(,));
} return ;
}

Codeforces Round #536 E. Lunar New Year and Red Envelopes /// 贪心 记忆化搜索 multiset取最大项的更多相关文章

  1. Codeforces Round #554 (Div. 2) D 贪心 + 记忆化搜索

    https://codeforces.com/contest/1152/problem/D 题意 给你一个n代表合法括号序列的长度一半,一颗有所有合法括号序列构成的字典树上,选择最大的边集,边集的边没 ...

  2. Codeforces Round 536 (Div. 2) (E)

    layout: post title: Codeforces Round 536 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  3. Codeforces Round #336 (Div. 2) D. Zuma 记忆化搜索

    D. Zuma 题目连接: http://www.codeforces.com/contest/608/problem/D Description Genos recently installed t ...

  4. Educational Codeforces Round 1 E. Chocolate Bar 记忆化搜索

    E. Chocolate Bar Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/prob ...

  5. Codeforces Round #406 (Div. 1) A. Berzerk 记忆化搜索

    A. Berzerk 题目连接: http://codeforces.com/contest/786/problem/A Description Rick and Morty are playing ...

  6. Codeforces Round #427 (Div. 2) Problem D Palindromic characteristics (Codeforces 835D) - 记忆化搜索

    Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th nu ...

  7. Codeforces Round #459 (Div. 2):D. MADMAX(记忆化搜索+博弈论)

    D. MADMAX time limit per test1 second memory limit per test256 megabytes Problem Description As we a ...

  8. Codeforces 1106E. Lunar New Year and Red Envelopes(DP)

    E. Lunar New Year and Red Envelopes 题意: 在长度为n的时间轴上,有k个红包,每个红包有领取时间段[s,t],价值w,以及领了个这个红包之后,在时间d到来之前无法再 ...

  9. Codeforces Global Round 23 D.Paths on the Tree(记忆化搜索)

    https://codeforces.ml/contest/1746/problem/D 题目大意:一棵n节点有根树,根节点为1,分别有两个数组 s[i] 顶点 i 的魅力值 c[i] 覆盖顶点 i ...

随机推荐

  1. NMS python实现

    import numpy as np ''' 目标检测中常用到NMS,在faster R-CNN中,每一个bounding box都有一个打分,NMS实现逻辑是: 1,按打分最高到最低将BBox排序 ...

  2. java 并发——ReentrantLock

    java 并发--ReentrantLock 简介 public class ReentrantLock implements Lock, java.io.Serializable { // 继承了 ...

  3. 响应式web开发的一些文章

    CSS Device Adaptation:关注 W3C 建议的 CSS 设备适配标准. “在 CSS 中使用 LESS 实现更多的功能”(作者:Uche Ogbuji,developerWorks, ...

  4. 程序性能优化之APK大小优化(六)下篇

    阿里P7移动互联网架构师进阶视频(每日更新中)免费学习请点击:https://space.bilibili.com/474380680 本篇文章将继续从微信资源混淆AndResGuard原理来介绍AP ...

  5. python面试题之下面这些是什么意思:@classmethod, @staticmethod, @property?

    回答背景知识 这些都是装饰器(decorator).装饰器是一种特殊的函数,要么接受函数作为输入参数,并返回一个函数,要么接受一个类作为输入参数,并返回一个类. @标记是语法糖(syntactic s ...

  6. spring中@注解的相关解释

    @Component:@Controller:@Service:@Repository 在annotaion配置注解中用@Component来表示一个通用注释用于说明一个类是一个spring容器管理的 ...

  7. Python之向函数传递元组和字典

    也可以在函数定义时加上这两个参数用以接收多余的参数哦~

  8. servlet的ServletConfig接口

    ServletConfig接口 A servlet configuration object used by a servlet container to pass information to a ...

  9. Ubuntu16.04+cuda9.0安装教程

    1.安装NVIDIA驱动 首先去官网(http://www.nvidia.cn/Download/index.aspx?lang=cn)查找适配自己电脑GPU的驱动,我的电脑驱动版本如下: 执行如下语 ...

  10. 第七章 yaml格式

    一.简单说明 yaml是一个可读性高,用来表达数据序列的格式.YAML 的意思其实是:仍是一种标记语言,但为了强调这种语言以数据做为中心,而不是以标记语言为重点 二.基本语法 缩进时不允许使用Tab键 ...