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


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: NM, 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.
1T100
1KM
1N,M2000
1LiRiN
 

 

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[2009][2009],lef[2009];
int main()
{
    scanf("%d",&t);
    for(int cas=1;cas<=t;cas++){
        memset(f,0,sizeof(f));
        memset(lef,INF,sizeof(lef));
        scanf("%d%d%d",&n,&m,&k);
        for(int i=1;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=0;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=k;j++){
                if(lef[i]==INF){
                    f[i][j]=f[i-1][j];
                    continue;
                }
                int tmp=lef[i]-1;
                f[i][j]=max(f[i-1][j],f[tmp][j-1]+(i-tmp));
                ans=max(ans,f[i][j]);
            }
        }
        printf("Case #%d: %d\n",cas,ans);
    }
    return 0;
}
复制代码

 

posted @   luckilzy  阅读(394)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 【杂谈】分布式事务——高大上的无用知识?
历史上的今天:
2016-12-12 *HDU1848 博弈
点击右上角即可分享
微信分享提示