【链接】 我是链接,点我呀:)

【题意】

给你k个红包,每个红包可以在si..ti的时间范围内拿走。
抢完红包之后你得到wi元,然后你需要在di+1时刻才能继续抢红包
时间是线性的从1..n
然后某个人可以阻止你在x时刻抢红包,然后你的时间跳过1s(-1s)直接到达x+1时刻.
这个人可以阻止你m次。
请问这个人采用最优阻止策略下,你最少抢到的金额。
(如果有多个可以抢的红包,那么抢wi最大的,如果仍然相同抢di最大的,再相同的话就无所谓了,因为选哪个都一样了)

【题解】

dp
设dp[i][j]表示i时刻已经用了j次阻止机会,后面能抢到的最少金额.
我们可以用sort+优先队列求出choose[i]
即表示i时刻你会选择哪一个红包(注意是排序后的红包QAQ)
那么在i时刻有两种选择
1.这个人进行干扰
那么转移到dp[i+1][j+1]
2.这个人不进行干扰
那么如果i时刻有的选
就转移到dp[a[choose[i]].d+1][j]+a[choose[i]].w
如果没得选就转移到dp[i+1][j]

每次取最小值就好

记得开long

【代码】

import java.io.*;
import java.util.*; public class Main { static InputReader in;
static PrintWriter out; static class RedEnvelope{
int s,t,d,w,id;
} public static Comparator<RedEnvelope> cmp1 = new Comparator<Main.RedEnvelope>() {
@Override
public int compare(RedEnvelope o1, RedEnvelope o2) {
return o1.s-o2.s;
}
}; public static Comparator<RedEnvelope> cmp2 = new Comparator<Main.RedEnvelope>() {
@Override
public int compare(RedEnvelope o1, RedEnvelope o2) {
if (o1.w==o2.w) {
return o2.d-o1.d;
}else {
return o2.w-o1.w;
}
}
}; static int N = (int)1e5;
static int n,m,k;
static RedEnvelope a[];
static int choose[];
static PriorityQueue<RedEnvelope> pq;
static long dp[][]; static long dfs(int t,int cnt) {
if (dp[t][cnt]!=-1) return dp[t][cnt];
if (t>n) return 0;
//打扰t时刻
long temp1 = (long)1e17;
if (cnt+1<=m) temp1 = Math.min(temp1, dfs(t+1,cnt+1)); //不打扰
long temp2 = (long)1e17;
if (choose[t]!=-1) {
temp2 = Math.min(temp2,dfs(a[choose[t]].d+1,cnt)+a[choose[t]].w);
}else {
temp2 = Math.min(temp2, dfs(t+1,cnt));
} dp[t][cnt] = Math.min(temp1, temp2);
return dp[t][cnt];
} public static void main(String[] args) throws IOException{
in = new InputReader();
out = new PrintWriter(System.out); //code start from here
a = new RedEnvelope[N+10];
for (int i = 1;i <= N;i++) a[i] = new RedEnvelope(); pq = new PriorityQueue<>(cmp2);
choose = new int[N+10];
dp = new long[N+10][200+10];
for (int i = 0;i <= N;i++)
for (int j = 0;j <= 200;j++)
dp[i][j] = -1; n = in.nextInt();m = in.nextInt();k = in.nextInt(); for (int i = 1;i <= k;i++) {
a[i].s = in.nextInt();
a[i].t = in.nextInt();
a[i].d = in.nextInt();
a[i].w = in.nextInt();
}
Arrays.sort(a, 1,k+1,cmp1);
for (int i = 1;i <= k;i++) a[i].id = i;//排完序再标号!QAQ
int j = 1; for (int i = 1;i <= n;i++) {
for (;j<=k;) {
if (a[j].s<=i) {
pq.add(a[j]);
j++;
}else break;
}
while (!pq.isEmpty()) {
RedEnvelope temp = pq.peek();
if (temp.t<i) {
pq.poll();
continue;
}
choose[i] = temp.id;
break;
}
if (pq.isEmpty()) choose[i] = -1;
} out.println(dfs(1,0));
out.close();
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader() {
br = new BufferedReader(new InputStreamReader(System.in));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
}
}
}

【Codeforces 1106E】Lunar New Year and Red Envelopes的更多相关文章

  1. 【Codeforces 1106E】 Lunar New Year and Red Envelopes

    Codeforces 1106 E 题意:有\(k\)个红包,第\(i\)个红包可以在\(s_i\)到\(t_i\)的时间内抢,同时获得\(w_i\)的钱,但是抢完以后一直到\(d_i\)都不可以继续 ...

  2. 【Codeforces 1106D】Lunar New Year and a Wander

    [链接] 我是链接,点我呀:) [题意] 让你遍历n个节点,访问过的节点不操作. 如果是没有访问过的点,那就把它加到序列的末尾. 问你形成的最小字典序的序列是多少. [题解] 显然每次找最小的标号 用 ...

  3. 【Codeforces 1106C】Lunar New Year and Number Division

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 看了下样例解释就懂了... 每次选择最大最小的两个组合 然后加起来.. [代码] import java.io.IOException; im ...

  4. 【Codeforces 1106B】Lunar New Year and Food Ordering

    [链接] 我是链接,点我呀:) [题意] 给你n个菜以及每个人需要的菜以及数量 如果某个人无法满足它对菜的需求的话 就用价格比较低的菜来填充它的要求. (如果价格低的菜不够了,那么就直接输出0) 否则 ...

  5. Codeforces #536 div2 E (1106E)Lunar New Year and Red Envelopes (DP)

    题意:过年了,Bob要抢红包.抢红包的时间段为1 - n,有m个红包,每个红包有三个属性:st(红包出现的时间), ed(红包消失的时间),d(如果抢了这个红包,能够抢下一个红包的时间),w(红包的收 ...

  6. Codeforces 1106 E. Lunar New Year and Red Envelopes 优先队列+dp

    题意大致是Bob新年拿红包,每个红包可以在s-t时间内取,但是取了之后得在d+1时间开始才能继续取红包. 同时他女儿能在m个时间点阻止他取红包,求女儿阻止后Bob取得的w总和最小值. Bob取红包的策 ...

  7. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  8. Codeforces 1106E. Lunar New Year and Red Envelopes(DP)

    E. Lunar New Year and Red Envelopes 题意: 在长度为n的时间轴上,有k个红包,每个红包有领取时间段[s,t],价值w,以及领了个这个红包之后,在时间d到来之前无法再 ...

  9. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

随机推荐

  1. [BZOJ 3126] Photo

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3126 [算法] 差分约束系统 注意SPFA判负环的条件应为 : 若所有点入队次数之和 ...

  2. union 的一个简单例子,搜狗笔试题

    union Test{   char a[4];    short b;};Test test;test.a[0]=256;test.a[1]=255;test.a[2]=254;test.a[3]= ...

  3. 70.资金管理-福利表管理 Extjs 页面

    1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8&quo ...

  4. MAC地址 初识

    MAC地址 即物理地址/硬件地址 地址长度为48位,6字节. 格式为:00-23-5A-15-99-42 一个网卡对应一个MAC地址(比如笔记本,有线网卡有一个MAC地址,无线网卡也有一个MAC地址) ...

  5. C. Searching for Graph(cf)

    C. Searching for Graph time limit per test 1 second memory limit per test 256 megabytes input standa ...

  6. 洛谷P1726 上白泽慧音(Tarjan强连通分量)

    P1726 上白泽慧音 题目描述 在幻想乡,上白泽慧音是以知识渊博闻名的老师.春雪异变导致人间之里的很多道路都被大雪堵塞,使有的学生不能顺利地到达慧音所在的村庄.因此慧音决定换一个能够聚集最多人数的村 ...

  7. Oh,mygoddess

    很早的时候就看了这一道题目 , 当时不会做 , 现在 边听歌边写无压力 ........ 题意 : 光辉骑士 一直都在 迷宫的右上角 , 第一行给你迷宫的规格 , 下面是迷宫 "O" ...

  8. 巴什博弈------最少取件数 不是1的情况下 hdu---2897

    最少取件数 是1的时候   核心代码是 // 共有 n 见 物品 一次最少取 一个 最多取 m 个 )==) printf("先取者输"); 在代码中  可以看到   题目中 一共 ...

  9. 363 Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K

    Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...

  10. [ NOIP 2009 ] TG

    \(\\\) \(\#A\) \(Spy\) 给出两个长度均为\(N\)相同的样例串,建立第一个串各个字符向第二个串对应位置字符的映射,并用映射转换给出的长度为\(M\)第三个串,输入保证只有大写字符 ...