Codeforces Round #536 (Div. 2) E dp + set
https://codeforces.com/contest/1106/problem/E
题意
一共有k个红包,每个红包在\([s_i,t_i]\)时间可以领取,假如领取了第i个红包,那么在\(d_i\)后才能领取下一个红包,每个红包价值\(w_i\),对方假如有机会领取红包他一定会领取,你有m次阻止对方领取的机会,问对方最少可以拿到多少红包
题解
- 定义dp[i][j]为前i秒用了j次机会让对方拿到最小价值的红包
- \(dp[i][j] - > dp[i+1][j+1]\) 假如使用阻止
- \(dp[i][j] - > dp[d[s]+1][j]\) 假如不用
- \(dp[i][j] - > dp[i+1][j]\) 这一秒没有可以领的红包
- 用set处理当前第i秒可以领的优先级最高的红包
代码
#include<bits/stdc++.h>
#define pii pair<int,int>
#define MAXN 100005
#define mk make_pair
#define inf 0x3f3f3f3f
#define ll long long
#define ft first
#define se second
using namespace std;
vector<pii>in[MAXN],out[MAXN];
multiset<pii>S;
int n,m,k,i,j,s,t,d,w;
ll dp[MAXN][205];
int main(){
cin>>n>>m>>k;
for(i=0;i<k;i++){
scanf("%d%d%d%d",&s,&t,&d,&w);
in[s].push_back(mk(w,d));
out[t+1].push_back(mk(w,d));
}
memset(dp,inf,sizeof(dp));
for(i=0;i<=m;i++)dp[1][i]=0;
for(i=0;i<=n;i++){
for(auto x:in[i])S.insert(x);
for(auto x:out[i])S.erase(S.find(x));
for(j=0;j<=m;j++){
auto p=S.begin();
if(p==S.end())
dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
else{
p=S.end();p--;
dp[p->se+1][j]=min(dp[i][j]+p->ft,dp[p->se+1][j]);
dp[i+1][j+1]=min(dp[i][j],dp[i+1][j+1]);
}
}
}
cout<<dp[n+1][m];
}
Codeforces Round #536 (Div. 2) E dp + set的更多相关文章
- Codeforces Round 536 (Div. 2) (E)
layout: post title: Codeforces Round 536 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- 严格递增类的dp Codeforces Round #371 (Div. 1) C dp
http://codeforces.com/contest/713 题目大意:给你一个长度为n的数组,每次有+1和-1操作,在该操作下把该数组变成严格递增所需要的最小修改值是多少 思路:遇到这类题型, ...
- 很好的一个dp题目 Codeforces Round #326 (Div. 2) D dp
http://codeforces.com/contest/588/problem/D 感觉吧,这道题让我做,我应该是不会做的... 题目大意:给出n,L,K.表示数组的长度为n,数组b的长度为L,定 ...
- Codeforces Round #548 (Div. 2) C dp or 排列组合
https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个 ...
- Codeforces Round #541 (Div. 2) G dp + 思维 + 单调栈 or 链表 (连锁反应)
https://codeforces.com/contest/1131/problem/G 题意 给你一排m个的骨牌(m<=1e7),每块之间相距1,每块高h[i],推倒代价c[i],假如\(a ...
- Codeforces Round #543 (Div. 2) F dp + 二分 + 字符串哈希
https://codeforces.com/contest/1121/problem/F 题意 给你一个有n(<=5000)个字符的串,有两种压缩字符的方法: 1. 压缩单一字符,代价为a 2 ...
- Codeforces Round #303 (Div. 2) C dp 贪心
C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #536 (Div. 2) F 矩阵快速幂 + bsgs(新坑) + exgcd(新坑) + 欧拉降幂
https://codeforces.com/contest/1106/problem/F 题意 数列公式为\(f_i=(f^{b_1}_{i-1}*f^{b_2}_{i-2}*...*f^{b_k} ...
- Codeforces Round #536 (Div. 2)
前言 如您所见这又是一篇咕了的文章,直接咕了10天 好久没打CF了 所以还是个蓝名菜鸡 机房所有人都紫名及以上了,wtcl 这次前4题这么水虽然不知道为什么花了1h,结果不知道为什么搞到一半出锅了,后 ...
随机推荐
- DBus send byte array over gdbus ----Send dbus data
遇到一个问题,如何通过dbus传送uint8数组元素 有3种方法, 1.直接传 ay 2.传 a(y) 3.xml定义为 ay,但是通过annotation 强行将 guchar 转为GVarian ...
- JOSN转列格式(csv文件)
推荐网站 https://json-csv.com/ 限制1M大小
- leetcode5
public class Solution { private int lo, maxLen; public String LongestPalindrome(String s) { int len ...
- leetcode31
class Solution { public: void nextPermutation(vector<int>&nums) { int len = nums.size(); , ...
- TP5 自定义验证器
TP内置验证功能提供两种验证方法 验证器(推荐) $validate = Validate::make([ 'id' => 'require|integer', ]); if ($validat ...
- T-SQL中CTE表 with关键字
Select字句在逻辑上是SQL语句最后进行处理的最后一步,所以,以下查询会发生错误: SELECT YEAR(OrderDate) AS OrderYear, COUNT(DISTINCT Cust ...
- rpm包安装的nginx热升级
文章目录一.本地环境基本介绍二.yum升级命令说明三.升级好nginx后如何不中断业务切换3.1.nginx相关的信号说明3.2.在线热升级nginx可执行文件程序一.本地环境基本介绍本次测试环境,是 ...
- cdnbest里如何查看网站是否被缓存
比如开启了强制缓存,如何查看缓存是否生效 本例以firefox浏览器查看,先打开浏览器,按下F12, 然后在浏览器是输入网址访问 如下图响应头里的 x-cache显示 Miss from 就是没有缓 ...
- 【VBA】セールの値は配列に変換方法
方法一 Sub test1() //変数の定義 Dim a() As Integer, iRow As Long, i As Integer //非空白のセールまでの行を取得 iRow = Cells ...
- 深入JVM之类的加载过程
类的加载—连接—初始化 加载:查找并加载类的字节码文件,从硬盘到内存. 类的加载指的是将类的.class文件中的二进制数据读入到内存中,将其放在运行时数据区的方法区内,然后在堆区创建一个java.la ...