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. idea最常使用的快捷键

    撤销 反撤销 : Ctrl+Z / Ctrl+Shift+Z 删除一行 : Ctrl+Y 跳到实现类 : Ctrl+Alt+B 重命名文件:   shift+F6 控制台放大缩小: ctrl+shif ...

  2. BUAAMOOC-Alpha版本发布说明

    BUAAMOOC-Alpha版本发布说明 本说明为BUAAMOOCv1.0版发布说明. 软件截图 上届软件截图 可以看到上届的界面做的很简陋,对于登录.查看课程列表.观看视频等操作需要跳转多个页面,视 ...

  3. 20162314 《Program Design & Data Structures》Learning Summary Of The Fifth Week

    20162314 2017-2018-1 <Program Design & Data Structures>Learning Summary Of The Fifth Week ...

  4. 利用Hibernate子查询(in) 得到部分字段(实体类的构造函数)

    感人= = 终于弄好了 String hql="select new Shop(s.strid,s.shopname,s.tradearea,s.discountinfo,s.beginti ...

  5. c++中的函数重载

    函数多态也称为函数重载. (1)函数重载指的是可以有多个同名的函数,因此对名称进行了重载. (2)函数重载的关键在于函数的参数列表,也称为函数特征标.如果两个函数的参数数目和参数类型相同,同时参数的排 ...

  6. 由一个滑动条的任务需求产生一个对UISlider控件的探讨

    任务需求样式:

  7. PAT 甲级 1142 Maximal Clique

    https://pintia.cn/problem-sets/994805342720868352/problems/994805343979159552 A clique is a subset o ...

  8. HDU 2140 Michael Scofield's letter

    http://acm.hdu.edu.cn/showproblem.php?pid=2140 Problem Description I believe many people are the fan ...

  9. mysql按日期分组统计数据

    最近在做一个招聘网时,需要显示一个月内企业招聘信息的发布数量,按日期分组统计,刚开始是直接从源数据库表里面进行group by,但这样子就出现日期不连续的问题了,我想要的效果是,若当天没有数据,则显示 ...

  10. [转帖]常见USB种类

    随着 USB Type-C 接口被苹果推上热门话题,那么对于我们普通的消费者来说,各种 USB 接口类型我们知道多少?买一个设备回来我们是否会遇到各种接口各种线用不了的情况呢? 那么我们泪雪网新开的一 ...