Alice’s Stamps

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 125    Accepted Submission(s): 34

Problem Description
Alice likes to collect stamps. She is now at the post office buying some new stamps.
There are N different kinds of stamps that exist in the world; they are numbered 1 through N. However, stamps are not sold individually; they must be purchased in sets. There are M different stamp sets available; the ith set contains the stamps numbered Li through Ri. The same stamp might appear in more than one set, and it is possible that one or more stamps are not available in any of the sets.
All of the sets cost the same amount; because Alice has a limited budget, she can buy at most K different sets. What is the maximum number of different kinds of stamps that Alice can get?
 
Input
The input starts with one line containing one integer T, the number of test cases.T test cases follow.
Each test case begins with a line containing three integers: N, M, and K: the number of different kinds of stamps available, the number of stamp sets available, and the maximum number of stamp sets that Alice can buy.
M lines follow; the ithoftheselinesrepresentsthei^{th} stamp set and contains two integers, Li and Ri, which represent the inclusive range of the numbers of the stamps available in that set.
1≤T≤100
1≤K≤M
1≤N,M≤2000
1≤Li≤Ri≤N
 
Output
For each test case, output one line containing “Case #x: y”, where x is the test case number (starting from 1) and y is the maximum number of different kinds of stamp that Alice could get.
 
Sample Input
2
5 3 2
3 4
1 1
1 3
100 2 1
1 50
90 100
 
Sample Output
Case #1: 4
Case #2: 50

Hint

In sample case #1, Alice could buy the first and the third stamp sets, which contain the first four kinds
of stamp. Note that she gets two copies of stamp 3, but only the number of different kinds of stamps
matters, not the number of stamps of each kind.
In sample case #2, Alice could buy the first stamp set, which contains 50 different kinds of stamps.

 
Source
 

题意:

有n种卡片1~n,m个卡包,每个卡包中包含一段连续的不重复的卡片,wen最多买k个卡包能够得到的最多的种类的卡片。

代码:

//n和k只有2000,可以用nk的方法,f[i][j]表示到达i位置使用了j个卡包的最大卡片种类数,先处理出来如果买了i卡片能够买到的左边的最远的那
//个卡片lef[i],这样就可以转移了,到达i位置考虑买还是不买,不买就由前一个转移,买就由lef[i]-1转移来。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int INF=0x3f3f3f3f;
int t,n,m,k,f[][],lef[];
int main()
{
scanf("%d",&t);
for(int cas=;cas<=t;cas++){
memset(f,,sizeof(f));
memset(lef,INF,sizeof(lef));
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
for(int j=x;j<=y;j++) lef[j]=min(lef[j],x);
}
int ans=;
for(int i=;i<=n;i++){
for(int j=;j<=k;j++){
if(lef[i]==INF){
f[i][j]=f[i-][j];
continue;
}
int tmp=lef[i]-;
f[i][j]=max(f[i-][j],f[tmp][j-]+(i-tmp));
ans=max(ans,f[i][j]);
}
}
printf("Case #%d: %d\n",cas,ans);
}
return ;
}

HDU 6249的更多相关文章

  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. Alice’s Stamps HDU - 6249 (区间DP)

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

  5. 区间DP || HDU 6249 Alice’s Stamps

    题意:标号为1-n的n种邮票,m个邮票集,每个集里有标号从Li到Ri的邮票,要从中选K个邮票集,使这K个邮票集能覆盖最多种的邮票,问最多能覆盖多少种邮票 思路:区间DP (我:??? f[i][j]表 ...

  6. D - 渣渣仰慕的爱丽丝 HDU - 6249(背包问题变形)

    爱丽丝喜欢集邮.她现在在邮局买一些新邮票. 世界上有各种各样的邮票;它们的编号是1到N.但是,邮票不是单独出售的;必须成套购买.有M套不同的邮票可供选择; 第i套包括编号从li到ri的邮票 .同一枚邮 ...

  7. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  9. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

随机推荐

  1. check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc

    往一个新建的MySQL表中插入数据报错 2018-08-22 14:09:18.875 ERROR 9256 --- [apr-8080-exec-9] o.s.b.w.servlet.support ...

  2. 【Alpha】阶段第七次Scrum Meeting

    [Alpha]阶段第七次Scrum Meeting 工作情况 团队成员 今日已完成任务 明日待完成任务 刘峻辰 增加上课信息接口 编写按学院搜索课程接口 赵智源 构建后测试点测试框架 构建前测试点测试 ...

  3. ME.kkkK

    ME.kkkK 一.预估与实际 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning 计划 50 40 • Estima ...

  4. Linux基础入门--04

    目录结构及文件基本操作 实验介绍: 1.Linux 的文件组织目录结构. 2.相对路径和绝对路径. 3.对文件的移动.复制.重命名.编辑等操作. 一.Linux 目录结构 在讲 Linux 目录结构之 ...

  5. 如何获取启动页activity

    启动页activity指App启动的第一个activity,介绍几种查看启动页activity的方法: 方法一:问开发,最有效的获取方式 方法二:dumpsys package 包名,前提是知道包名( ...

  6. 转载 intellij IDEA 使用体验 (本人感觉它的使用是一种趋势)

    从去年开始转java以来,一直在寻找一款趁手的兵器,eclipse虽然是很多java程序员的首选,但是我发现一旦安装了一些插件,workspace中的项目达到数10个以后,经常崩溃,实在影响编程的心情 ...

  7. C#编程概述

    一个简单的c#程序 标识符 标识符是一种字符串,用来命名变量.方法.参数和许多后面将要阐述的其他程序结构. 关键字 所有C#关键字都由小写字母组成,但是.NET类型名使用Pascal大小写约定. Ma ...

  8. Sprint计划(未完成)

    1.需求预计:http://www.cnblogs.com/OuZeBo/p/4529320.html 2.功能设计: 3.Spring计划:

  9. Scrum项目6.0 和8910章读后感

    Scrum项目6.0总结 这次sprint1通过我们的努力,终于把自动回复做出来了.但之后的任务更加繁重,我们要更加努力,克服各种困难. 也要说说这次自动回复里面的注意之处: 1.不该空格的地方空格, ...

  10. Linux 压缩 解压缩 命令相关

    1.命令格式:tar[必要参数][选择参数][文件] 2.命令功能:用来压缩和解压文件.tar本身不具有压缩功能.他是调用压缩功能实现的 3.命令参数:必要参数有如下:-A 新增压缩文件到已存在的压缩 ...