Lunar New Year and Red Envelopes CodeForces - 1106E (dp)

Posted uid001

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Lunar New Year and Red Envelopes CodeForces - 1106E (dp)相关的知识,希望对你有一定的参考价值。

大意: 总共$n$的时间, $k$个红包, 红包$i$只能在时间$[s_i,t_i]$范围内拿, 并且拿完后时间跳到$d_i+1$,Bob采用贪心策略,每个时间点若有红包能取则取钱数$w_i$最大的, $w_i$相同则取$d_i$最大的, Alice有$m$次机会让Bob跳过一个时间, 求Alice如何操作能使Bob得到钱数最少.

 

比较简单的DP, 记$dp[i][j]$为$i$时刻还能干扰$j$次的最小收益

$dp[i][j]=min(dp[d_i][j]+w_i,dp[i+1][j-1])$, $(w_i,d_i)$为$i$时刻的贪心策略

用一个堆维护一个最优的(w,d)来转移即可

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define w first
#define d second
#define io std::ios::sync_with_stdio(false)
#define endl ‘
‘
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head

const int N = 1e5+10;

int n, m, k, t;
struct _ {
	int s,t,d,w;
	bool operator < (const _ &rhs) const {
		return pii(w,d) < pii(rhs.w,rhs.d);
	}
} a[N];
ll dp[N][202];
priority_queue<_> q;

int main() {
	scanf("%d%d%d", &n, &m, &k);
	REP(i,1,k) {
		scanf("%d%d%d%d",&a[i].s,&a[i].t,&a[i].d,&a[i].w);
	}
	sort(a+1,a+1+k,[](_ a,_ b){return a.t<b.t;});
	memset(dp,0x3f,sizeof dp);
	REP(i,0,m) dp[n+1][i]=0;
	int now = k;
	PER(i,1,n) {
		while (now>0&&a[now].t>=i) q.push(a[now--]);
		while (q.size()&&q.top().s>i) q.pop();
		if (q.empty()) {
			REP(j,0,m) dp[i][j]=dp[i+1][j];
			continue;
		}
		int d=q.top().d,w=q.top().w;
		dp[i][0] = dp[d+1][0]+w;
		REP(j,1,m) dp[i][j]=min(dp[d+1][j]+w,dp[i+1][j-1]);
	}
	printf("%lld
", dp[1][m]);
}

 

以上是关于Lunar New Year and Red Envelopes CodeForces - 1106E (dp)的主要内容,如果未能解决你的问题,请参考以下文章

Lunar New Year and Red Envelopes CodeForces - 1106E (dp)

线段树or优先队列+dp E. Lunar New Year and Red Envelopes

Codeforces Round #536 E. Lunar New Year and Red Envelopes /// 贪心 记忆化搜索 multiset取最大项

Lunar New Year and a Wander

B. Lunar New Year and Food Ordering

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