题意为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));
}
}