题目大意:

给定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. 用Python实现一个简单的猜数字游戏

    import random number = int(random.uniform(1,10)) attempt = 0 while (attempt < 3): m = int(input(' ...

  2. 【webpack】webpack之postcss-loader的基本使用---【巷子】

    一.postcss-loader简介 postcss-loader 用来对.css 文件进行处理,并添加在 style-loader 和 css-loader 之后.通过一个额外的 postcss 方 ...

  3. 巧妙的使用jmeter来发送json格式数据

    1. header-manager 修改content-type值. 如果不修改该值, 则默认会是urlencode的数据格式(例如a=5&b=6). 修改为json后,会告诉服务器,发送的数 ...

  4. 笔记60 Spring+Mybatis整合

    整合思路:将SessionFactory交给Spring管理,并且把Mapper和XML结合起来使用. 一.目录结构 二.基本的pojo Category.java package com.pojo; ...

  5. kubernetes报错

    错误信息:执行yaml文件后,服务在运行,但是提示命令找不到 原因:没有环境,相当于只有一个快捷方式 环境目录为/usr/local/bin 解决办法:将/etc/ansible/bin下的文件都拷贝 ...

  6. Python中 将数据插入到Word模板并生成一份Word

    搬运出处: https://blog.csdn.net/DaShu0612/article/details/82912064

  7. C++32位和64位常见类型的大小

             32位      64位 char      1       1 int                       4      大多数4,少数8 long      4      ...

  8. 路由网关--spring cloud zuul

    路由网关--spring boot Zuul 1.为什么需要Zuul? Zuul Ribbon 以及 Eureka 相结合,可以实现智能路由和负载均衡的功能, Zuul 能够将请求流量按某种策略分发到 ...

  9. 外部操作获取iframe的东西

    原生js  document.iframe[id].contentWindow.document.querySelector(el).innerHTML    jq    $(window.ifram ...

  10. fiddler增加ip以及响应时间列

    最近打算看一下移动端app的响应等请求,这里打算用fillder来查看appium的模拟出发请求的操作来查看结果, 所以我们需要在左侧的面板增加我们所需要的ip,响应时间等数据以方便我们查看 fidd ...