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];
}

原文地址:https://www.cnblogs.com/VIrtu0s0/p/10628982.html

时间: 2024-08-27 13:56:07

Codeforces Round #536 (Div. 2) E dp + set的相关文章

Codeforces Round #261 (Div. 2) E (DP)

E. Pashmak and Graph Pashmak's homework is a problem about graphs. Although he always tries to do his homework completely, he can't solve this problem. As you know, he's really weak at graph theory; so try to help him in solving the problem. You are

Codeforces Round #536 (Div. 2)

目录 Codeforces Round #536 (Div. 2) A 题目大意 题解 卡点 C++ Code: B 题目大意 题解 卡点 C++ Code: C 题目大意 题解 卡点 C++ Code: D 题目大意 题解 卡点 C++ Code: E 题目大意 题解 卡点 C++ Code: F 题目大意 题解 卡点 C++ Code: Codeforces Round #536 (Div. 2) A 题目大意 给你一个\(n\times n(n\leqslant500)\)的矩阵,只包含.

Codeforces Round #536 (Div. 2) - D. Lunar New Year and a Wander(最短路)

Problem  Codeforces Round #536 (Div. 2) - D. Lunar New Year and a Wander Time Limit: 3000 mSec Problem Description Input Output Output a line containing the lexicographically smallest sequence a1,a2,…,an Bob can record. Sample Input 3 21 21 3 Sample

Codeforces Round #548 (Div. 2) C dp or 排列组合

https://codeforces.com/contest/1139/problem/C 题意 一颗有n个点的树,需要挑选出k个点组成序列(可重复),按照序列的顺序遍历树,假如经过黑色的边,那么这个序列就是好的,问有多少个好的序列 题解 黑边不连,红边连,假如两个点不在同一并查集,那么一定经过黑边 定义\(dp[i][j][k]\)为选择前i个点,起始点为j,是否已经经过黑边(k)的方案数 \(dp[i-1][j][0]*(n-N[fin(j)])+dp[i-1][j][1]*n - > dp

Codeforces Round #156 (Div. 1)A dp

//对每个数进行一个编号, //dp[i][j]表示第i个数其前面是第j个数得到的最长子序列 //dp[i][j] =  dp[i][j] = dp[last[j]][map[num[i]]] + 1; //last[j]是编号为j的数的最后出现的位置 //map[num[i]]第i个数的编号 #include<iostream> #include<cstdio> #include<cstring> using namespace std ; const int max

Codeforces Round #144 (Div. 1) B dp

//第i列和第i+n的涂色个数是相同的,所以只需要处理前n列 //dp[i][j]表示前i列有j个涂色的方法数 //dp[i][j] += dp[i-1][s]*pow(c[n][s] , m/n) //c[n][s] 表示从n个数中取s的组合数 #include<cstdio> #include<cstring> #include<iostream> using namespace std ; const int maxn = 110 ; const __int64

Codeforces Round #162 (Div. 1) B dp

//存入所有数的素数因数 //若两个数不互质,那么他们之间必然有素数因数 //dp[i][0]表示第i个数不选前i个数中能得到的最长序列 //dp[i][1]表示选了第i个数 //dp[i][0] = max(dp[i-1][0] , dp[i-1][1]) //dp[i][1] = max(dp[pos][1] + 1 ,dp[i][1] ); //pos位第i个数的质数因子出现的最后一个位置 #include<cstdio> #include<cstring> #include

Codeforces Round #302 (Div. 2)——C dp—— Writing Code

Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly ai bugs in every line of code that he writes. Let's call a sequence of non

Codeforces Round #363 (Div. 2) C dp或贪心 两种方法

Description Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day