(构造/搜索)cf#536-E

题意为bob有一种选择策略,在x时间会按w大,d大的选择,而选了i-th个,就只能选择di时间之后的红包。
我们需要处理出每个时间能选的最优红包,再dp或记忆化搜索出alice的选择
in数组处理i-th加入的红包,out处理i-th时间删除的红包
multiset<pair<int, int>>会按pair的第一个元素排序,.rbegin()即是最大的元素

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
const int maxm = 200 + 5;
vector< pair<ll, ll> > in[maxn], out[maxn];
multiset< pair<ll, ll> >now;
pair<ll, ll> best[maxn];
ll n, m, k;
ll dp[maxn][maxm];
ll dfs(int pos, int c) {
    if(pos > n) return 0ll;
    if(dp[pos][c] >= 0ll) return dp[pos][c];
    ll res = best[pos].first + dfs(best[pos].second + 1, c);
    if(c < m) res = min(res, dfs(pos + 1, c + 1));
    return dp[pos][c] = res;
}
int main()
{
    while(~scanf("%d%d%d", &n, &m, &k)) {
        for(int i = 1; i <= n + 1; i++) in[i].clear(), out[i].clear();
        memset(dp, -1, sizeof(dp));
        now.clear();
        ll s, t, d, w;
        for(int i = 0; i < k; i++) {
            scanf("%lld%lld%lld%lld", &s, &t, &d, &w);
            in[s].push_back(make_pair(w, d));
            out[t + 1].push_back(make_pair(w, d));
        }
        for(int i = 1; i <= n + 1; i++) {
            for(int j=0;j<in[i].size();j++)
                now.insert(in[i][j]); // 加入可取的
            for(int j=0;j<out[i].size();j++)
                now.erase(now.find(out[i][j])); // 去掉不可取的
            if(now.size()) best[i] = *now.rbegin();
            else best[i] = {0ll, (ll)i};
        }
        printf("%I64d\n", dfs(1, 0));
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值