Codeforces Round 536 (Div. 2) (E)
layout: post
title: Codeforces Round 536 (Div. 2)
author: "luowentaoaa"
catalog: true
tags:
mathjax: true
- codeforces
- DP
- 数据结构
前四题签到题不讲,
E.Lunar New Year and Red Envelopes (DP+数据结构)
题意
有k个红包,每个红包可以在一个时间段拿起,并且在拿起之后知道D时间都不能拿其他红包
如果在某一时刻可以拿红包会拿金额最大的,如果金额同样大会拿D最大的,
有m次干扰的机会,可以让在某一时刻不能拿红包。
问最少可以得到多少金额
题意
首先,每一时刻拿哪个红包和时间D都已经固定了,于是我们就直接构造dp转移一下就行
\]
那么对于一个时刻,如果没有红包那么就直接转移到下一时间
\]
如果可以抢红包那么,
\]
\]
然后这题的很多解法的DP都差不多,主要差别是如何获取每一时间的最优金额和D的,
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int maxn=1e5+20;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
ll dp[maxn][205];
int n,m,k;
struct node{
int w,d;
void add(int ww,int dd){
if(ww>w)w=ww,d=dd;
if(ww==w&&dd>d)d=dd;
}
}my[maxn<<2];
void down(int i){
my[i<<1].add(my[i].w,my[i].d);
my[i<<1|1].add(my[i].w,my[i].d);
}
void update(int i,int l,int r,int ql,int qr,int w,int d){
if(l>=ql&&r<=qr){
my[i].add(w,d);
return;
}
int mid=(l+r)/2;
down(i);
if(ql<=mid)update(i<<1,l,mid,ql,qr,w,d);
if(qr>mid)update(i<<1|1,mid+1,r,ql,qr,w,d);
}
node query(int i,int l,int r,int pos){
if(l==r){
return my[i];
}
down(i);
int mid=(l+r)/2;
if(pos<=mid)query(i<<1,l,mid,pos);
else query(i<<1|1,mid+1,r,pos);
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
cin>>n>>m>>k;
for(int i=1;i<=k;i++){
int s,t,d,w;
cin>>s>>t>>d>>w;
update(1,1,n,s,t,w,d);
}
memset(dp,inf,sizeof(dp));
for(int i=0;i<=m;i++)dp[1][i]=0;
for(int i=1;i<=n;i++){
node now=query(1,1,n,i);
int w=now.w;int d=now.d;
for(int j=0;j<=m;j++){
if(d){
dp[d+1][j]=min(dp[d+1][j],dp[i][j]+w);
dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]);
}
else
dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
}
}
ll ans=inf;
for(int i=0;i<=m;i++)ans=min(ans,dp[n+1][i]);
cout<<ans<<endl;
return 0;
}
Codeforces Round 536 (Div. 2) (E)的更多相关文章
- 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) E dp + set
https://codeforces.com/contest/1106/problem/E 题意 一共有k个红包,每个红包在\([s_i,t_i]\)时间可以领取,假如领取了第i个红包,那么在\(d_ ...
- Codeforces Round #536 (Div. 2)--1106D - Lunar New Year and a Wander
https://codeforces.com/contest/1106/problem/D 题意:求出字典序最小的走法 解法:走到每个点,都选取与这个点连通的序号最小的点,并且这个序号最小的点没有被访 ...
- Codeforces Round #536 (Div. 2)
前言 如您所见这又是一篇咕了的文章,直接咕了10天 好久没打CF了 所以还是个蓝名菜鸡 机房所有人都紫名及以上了,wtcl 这次前4题这么水虽然不知道为什么花了1h,结果不知道为什么搞到一半出锅了,后 ...
- Codeforces Round #536 (Div. 2) B. Lunar New Year and Food Ordering
#include <bits/stdc++.h> #define N 300010 #define PII pair<int, int> using namespace std ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
随机推荐
- The XOR Largest Pair
刷刷书上的例题 在给定的N个整数A1,A2……An中选出两个进行XOR运算,得到的结果最大是多少?N<=105,0<=Ai<231 SOlution: 我们思考到对于两个数相异或,是 ...
- 国内各运营商(ISP)IP段表
国内各运营商(ISP)IP段表 来源:http://bbs.hh010.com/forum.php?mod=viewthread&tid=490529&orderby=dateline ...
- HDU 6203 ping ping ping(贪心+LCA+DFS序+BIT)
ping ping ping Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 菜单 & 工具栏 & 状态栏
MFC中ON_UPDATE_COMMAND_UI和ON_COMMAND消息区别 CCmdUI 加载状态栏 加载工具栏
- [Leetcode] first missing positve 缺失的第一个正数
Given an unsorted integer array, find the first missing positive integer. For example,Given[1,2,0]re ...
- [Leetcode] Best time to buy and sell stock iii 买卖股票的最佳时机
Say you have an array for which the i th element is the price of a given stock on day i. Design an a ...
- (一)STM32固件库详解(转载)
本篇博文是转载自emouse,因为不能直接转载,所以是复制过来再发布的. emouse原创文章,转载请注明出处http://www.cnblogs.com/emouse/ 1.1 基于标准外设库的 ...
- debounce 与 throttle 区别
原文地址:http://undefinedblog.com/debounce-and-throttle/ 二.什么是debounce 1. 定义 如果用手指一直按住一个弹簧,它将不会弹起直到你松 ...
- [链接] Linux下常见的~/.bashrc、/etc/profile、/etc/ld.so.config小科普以及caffe编译遇到的相关问题解决
由于博主设置禁止转载,这里贴一个链接,http://blog.csdn.net/u014266895/article/details/61928602,内容很有用,linux下很多软件问题都是各种路径 ...
- eclipse tomcat 插件
下载地址http://www.eclipsetotale.com/tomcatPlugin.html#A3