题目大意:

给定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. mac、windows系统charles安装破解

    一.下载 官网下载适合自己电脑的最新版本 下载地址:https://www.charlesproxy.com/latest-release/download.do 二.破解 破解地址:https:// ...

  2. @RequestParam 引发的编译问题

    在使用SpringMVC绑定基本类型(如String,Integer等)参数时,应通过@RequestParam注解指定具体的参数名称,否则,当源代码在非debug模式下编译后,运行时会引发Handl ...

  3. linux中errno及perror的应用

    1 perror 定义在头文件<stdlib.h>中 void perror(const char *s);函数说明 perror ( )用 来 将 上 一 个 函 数 发 生 错 误 的 ...

  4. 【小程序】获取到的e.target与e.currentTarget区别

    [小程序]获取到的e.target与e.currentTarget区别:https://blog.csdn.net/qq_33744228/article/details/80310294 使用e.t ...

  5. Python之Tab键自动补全

    首先备份一下Tab键自动补全代码: # python start file import sys import readline import rlcompleter import atexit im ...

  6. Sed的查,删,增,改

    sed的查,删,增,改 1.sed的查找 2.sed的删除 3.sed的上下左右增加文件内容 4.sed的改

  7. 发布后台接口报错:could not load file or assembly 'mysql.data,' version=6.7.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d

    本地调试正常,但是服务器上面一直报错:could not load file or assembly 'mysql.data,' version=6.7.4.0, Culture=neutral, P ...

  8. express 的路由学习

    使用步骤 - :获取路由中间件对象 `let router = express.Router();` - :配置路由规则 `router.请求方式(URL,fn事)` - fn中参数有req,res, ...

  9. Python改变当前工作目录

    import os print(os.getcwd()) # 打印当前工作目录 os.chdir('/Users/<username>/Desktop/') # 将当前工作目录改变为`/U ...

  10. vue 页面回退mounted函数不执行的问题及解决方法

    前言 最近做项目碰到一个很头大的问题--从a页面跳到b页面进行编辑,编辑完再返回a页面,却没走a页面的钩子函数mounted,数据没有更新 经过一番面向百度研究,终于找到了问题所在.接下来就记录一下这 ...