HDU 6249
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
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?
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
5 3 2
3 4
1 1
1 3
100 2 1
1 50
90 100
Case #2: 50
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.
题意:
有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的更多相关文章
- HDU 6249 Alice’s Stamps(2017 CCPC-Final G题,DP)
题目链接 HDU 6249 题意 给定$m$个区间,在这些区间中选出不超过$k$个,求被覆盖的点的数量的最大值. 设$f[i][j]$表示选到第$i$个点并选了$j$个区间的时候能得到的最大答案. 处 ...
- HDU 6249 Alice’s Stamps(dp)
http://acm.hdu.edu.cn/showproblem.php?pid=6249 题意: 给出n个区间,求选k个区间的最大区间并. 思路: 可能存在左端点相同的多个区间,那么此时我们肯定选 ...
- HDU 6249 Alice’s Stamps
[题目链接] 题目大意: 说有$m$个区间,要求选出不超过$k$个区间,使这些区间覆盖的长度最长,问最长长度是多少. 题解: 所有区间按$R$从小到大排序之后可以进行$dp$. $dp[i][j]$表 ...
- Alice’s Stamps HDU - 6249 (区间DP)
点击传送 Alice’s Stamps Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- 区间DP || HDU 6249 Alice’s Stamps
题意:标号为1-n的n种邮票,m个邮票集,每个集里有标号从Li到Ri的邮票,要从中选K个邮票集,使这K个邮票集能覆盖最多种的邮票,问最多能覆盖多少种邮票 思路:区间DP (我:??? f[i][j]表 ...
- D - 渣渣仰慕的爱丽丝 HDU - 6249(背包问题变形)
爱丽丝喜欢集邮.她现在在邮局买一些新邮票. 世界上有各种各样的邮票;它们的编号是1到N.但是,邮票不是单独出售的;必须成套购买.有M套不同的邮票可供选择; 第i套包括编号从li到ri的邮票 .同一枚邮 ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
随机推荐
- 深入 JSX
从本质上讲,JSX 只是为 React.createElement(component, props, ...children) 函数提供的语法糖.JSX代码: 1 2 3 <MyButton ...
- [linux] LVM原磁盘扩容(非增加磁盘)
阿里云机器,ECS运行时磁盘由300G扩容到500,重启机器生效后登录.可以看到/data目录总大小300G,/dev/vdb已经扩容到500G. [root@HD1g-elasticsearch2 ...
- iOS - Bundle 资源文件包生成和常见资源文件使用
1.Bundle 文件 Bundle 文件,就是资源文件包.我们将许多图片.XIB.文本文件组织在一起,打包成一个 Bundle 文件.方便在其他项目中引用包内的资源. Bundle 文件是静态的,也 ...
- Nginx是如何配置为 Web 服务器的【转载】
详解 Nginx是如何配置为 Web 服务器的 林涛 发表于:2016-11-29 23:23 分类:WebServer 标签:Nginx,web,web服务器 521次 抽象来说,将 Nginx 配 ...
- Scrum立会报告+燃尽图(十二月八日总第三十九次):制定视频方案
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2284 项目地址:https://git.coding.net/zhang ...
- 互评Beta版本——杨老师粉丝群——Pinball
互评beta版本 杨老师粉丝群——<PinBall> 一.基于NABCD评论作品,及改进建议 1.根据(不限于)NABCD评论作品的选题 (1)N(Need,需求) 随着年龄的增长, ...
- 在写ssh项目时浏览器页面出现http status 404 – not found
HTTP Status 404 - /streetManager/index.jsp type Status report message /streetManager/index.jsp descr ...
- 微信小程序配置文件记录
最近公司要求,需要研究微信方面的问题,我有幸被选中了,一周时间,研究透做出个小程序来.我就从简单的开始了,记录一下,以后忘了,好来翻阅 app.json 配置文件 配置文件上写:是由哪些页面组成,配置 ...
- Navicat for MySQL笔记1
1.MySQL数据库的基本操作 A.系统数据库 安装MySQL数据库服务器后,自带的数据库. B.用户数据库 用户根据实际需求所创建的数据库. C.数据库对象 表.视图.存储过程.函数.触发器以及事件 ...
- poj 3311(状态压缩DP)
poj 3311(状态压缩DP) 题意:一个人送披萨从原点出发,每次不超过10个地方,每个地方可以重复走,给出这些地方之间的时间,求送完披萨回到原点的最小时间. 解析:类似TSP问题,但是每个点可以 ...