题意:标号为1-n的n种邮票,m个邮票集,每个集里有标号从Li到Ri的邮票,要从中选K个邮票集,使这K个邮票集能覆盖最多种的邮票,问最多能覆盖多少种邮票

思路:区间DP (我:???

f[i][j]表示从1 - i 位置选择 j 个集合的覆盖种数

首先它可以从f[i][j] = max(f[i][j], max(f[i-1][j], f[i][j-1]))转移来

其次考虑它能转移到的点

用up[i] 记录覆盖i点的线段最右的点,如果要在 i 后面加一条线段,那么肯定优先取这个(因为它最右,同样加一条线段得到的覆盖长度更长

所以f[i][j]可以转移到f[up[i]][j],       if(up[i]) f[up[i]][j] = max(f[i-1][j-1]+up[i]-i+1, f[up[i]][j]);

嘤嘤嘤的哭了

区间DP的话,把区间排个序,然后去掉有完全包含的区间~

#include <map>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = ;
const int maxm = ;
struct node
{
int l, r;
}a[maxn];
bool cmp(node x, node y)
{
if(x.l != y.l) return x.l<y.l;
return x.r<y.r;
}
int up[maxn], f[maxn][maxn];
int main()
{
int T, tt=;
scanf("%d", &T);
while(T--)
{
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
memset(up, , sizeof(up));
memset(f, , sizeof(f));
for(int i = ; i <= m; i++)
{
scanf("%d%d", &a[i].l, &a[i].r);
for(int j = a[i].l; j <= a[i].r; j++)
up[j] = max(up[j], a[i].r);
}
sort(a+, a++m, cmp);
for(int i = ; i <= n; i++)
{
for(int j = ; j <= k; j++)
{
f[i][j] = max(f[i][j], max(f[i-][j], f[i][j-]));
if(up[i]) f[up[i]][j] = max(f[up[i]][j], f[i-][j-]+up[i]-i+);
}
}
/*for(int i = 1; i <= n; i++)
for(int j = 1; j <= k; j++)
printf("f[%d][%d] = %d\n", i, j, f[i][j]);*/
printf("Case #%d: %d\n", ++tt, f[n][k]);
}
return ;
}

区间DP || HDU 6249 Alice’s Stamps的更多相关文章

  1. HDU 6249 Alice’s Stamps(2017 CCPC-Final G题,DP)

    题目链接 HDU 6249 题意 给定$m$个区间,在这些区间中选出不超过$k$个,求被覆盖的点的数量的最大值. 设$f[i][j]$表示选到第$i$个点并选了$j$个区间的时候能得到的最大答案. 处 ...

  2. HDU 6249 Alice’s Stamps(dp)

    http://acm.hdu.edu.cn/showproblem.php?pid=6249 题意: 给出n个区间,求选k个区间的最大区间并. 思路: 可能存在左端点相同的多个区间,那么此时我们肯定选 ...

  3. HDU 6249 Alice’s Stamps

    [题目链接] 题目大意: 说有$m$个区间,要求选出不超过$k$个区间,使这些区间覆盖的长度最长,问最长长度是多少. 题解: 所有区间按$R$从小到大排序之后可以进行$dp$. $dp[i][j]$表 ...

  4. 区间DP HDU 4283

    t个数据 n个权值 1->n 可以入栈调整顺序 花费 第k个出来 w[i]*(k-1); 求花费最少 #include<stdio.h> #include<string.h&g ...

  5. 区间DP HDU 2476

    两个字符串s1,s2 从s1->s2 最少刷几次 刷 i->j 都变成一样的+1 #include<stdio.h> #include<string.h> usin ...

  6. Alice’s Stamps HDU - 6249 (区间DP)

    点击传送 Alice’s Stamps Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  7. hdu 4597 Play Game 区间dp

    Play Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=459 ...

  8. HDU 4283---You Are the One(区间DP)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4283 Problem Description The TV shows such as Y ...

  9. HDU 4293---Groups(区间DP)

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4293 Problem Description After the regional con ...

随机推荐

  1. Centos系统真机安装,U盘方式

    下载Centos系统镜像,建议选择Minimal ISO.下载地址:https://www.centos.org/download/ 下载Fedora Media Writer,用来将系统镜像写到U盘 ...

  2. 如何升级xcode 中的cocos2dx 到v2.2.2以上版本

    每次升级cocos2dx版本都觉得不知道怎么弄才行. 这次升级到v2.2.2版本又花了我不少时间.因此在这里分享一下,以后也有地方可以查询. 1. 到http://cocos2d-x.org/ 下载最 ...

  3. js 将json字符串转换为json对象的方法解析-转

    例如: JSON字符串:var str1 = '{ "name": "cxh", "sex": "man" }'; JS ...

  4. TensorFlow图像处理函数

    参考书 <TensorFlow:实战Google深度学习框架>(第2版) 图像编码处理+图像大小调整+图像翻转+图像色彩调整+处理标注框 #!/usr/bin/env python # - ...

  5. iOS [CIContext initWithOptions:]: unrecognized selector sent to instance 模拟器 iOS 8.4

    在模拟器(iPhone 4s,iOS 8.4)中运行应用时, 应用crash在了使用CIContext(options:nil) 这个API的一个纯Swift第三方库. StackOverFlow的解 ...

  6. mysql-SQL语法

    细节查询:http://www.w3school.com.cn/sql/index.asp 1 DDL-data difinition lanuage数据定义语句 使我们有能力创建或删除表格,我们也可 ...

  7. UVA - 1658 Admiral

    3. C - Admiral 题意:给定v(3<=v<=1000)个节点,e(3<=e<=10000)条边的又向加权图,求1->v的两条不相交的路径,使得权和最小. 思路 ...

  8. Codeforces Round #408 (Div. 2) B

    Description Zane the wizard is going to perform a magic show shuffling the cups. There are n cups, n ...

  9. 线段树/树状数组 POJ 2182 Lost Cows

    题目传送门 题意:n头牛,1~n的id给它们乱序编号,已知每头牛前面有多少头牛的编号是比它小的,求原来乱序的编号 分析:从后往前考虑,最后一头牛a[i] = 0,那么它的编号为第a[i] + 1编号: ...

  10. Linux下文件权限的设置

    文件/目录权限设置命令:chmod 这是Linux系统管理员最常用到的命令之一,它用于改变文件或目录的访问权限.该命令有两种用法: 用包含字母和操作符表达式的文字设定法 ) 其语法格式为:chmod ...