点击传送

Alice’s Stamps

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

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.

 
题意:给出n个区间,求选k个区间的最大区间并。

思路:可能存在左端点相同的多个区间,那么此时我们肯定选右端点最大的那个区间。现在将区间按左端点排序,d[i][j]表示在1~i坐标轴范围内选择j个区间的最大区间并。

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<stack>
#include<cstdlib>
#include <vector>
#include <set>
#include<queue>
#include<map>
using namespace std; #define ll long long
#define llu unsigned long long
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
const int maxn = 2e3+;
const ll mod = 1e9+;
const double eps = 1e-; int n,m,k;
int dp[maxn][maxn]; struct node
{
int l,r;
}s[maxn]; bool cmp(node x,node y)
{
return x.l < y.l;
}
int main()
{
int t;
scanf("%d",&t);
int ca = ;
while(t--)
{
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<=m;i++)
scanf("%d%d",&s[i].l,&s[i].r);
memset(dp,,sizeof dp);
sort(s+,s+m+,cmp);
int num = ;
int pos = ;
for(int len = ;len < n;len++)
{
for(pos;pos<=m;)
{
if(s[pos].l == len+) {
num = max(num, s[pos].r - s[pos].l + );
pos++;
}
else
break;
} for(int j=;j<=k;j++)
{
dp[len+][j] = max(dp[len+][j],dp[len][j]);
dp[len+num][j+] = max(dp[len][j]+num,dp[len+num][j+]);
}
if(num)
num--;
}
printf("Case #%d: %d\n",ca++,dp[n][k]);
}
}

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

  1. hdu 4283 区间dp

    You Are the One Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  2. HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化

    HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化 n个节点n-1条线性边,炸掉M条边也就是分为m+1个区间 问你各个区间的总策略值最少的炸法 就题目本身而言,中规中矩的 ...

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

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

  4. String painter HDU - 2476 -区间DP

    HDU - 2476 思路:分解问题,先考虑从一个空串染色成 B串的最小花费 ,区间DP可以解决这个问题 具体的就是,当 str [ l ] = = str [ r ]时 dp [ L ] [ R ] ...

  5. HDU 4632 区间DP 取模

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4632 注意到任意一个回文子序列收尾两个字符一定是相同的,于是可以区间dp,用dp[i][j]表示原字 ...

  6. 2016 ACM/ICPC Asia Regional Shenyang Online 1009/HDU 5900 区间dp

    QSC and Master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  7. HDU 4570(区间dp)

    E - Multi-bit Trie Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  8. hdu 2476 区间dp

    题意: 给出两个串s1和s2,一次只能将一个区间刷一次,问最少几次能让s1=s2 例如zzzzzfzzzzz,长度为11,我们就将下标看做0~10 先将0~10刷一次,变成aaaaaaaaaaa 1~ ...

  9. hdu 4632(区间dp)

    Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65535 K (Java/ ...

随机推荐

  1. React 内部属性与函数

    constructor 构造函数,在创建组件的时候调用一次. 例子: class TodoList extends React.Component { constructor(props, conte ...

  2. canvas实例(基础)

    JS实现五子棋大战:GitHub源码 知识点总结: 第一步.基础: //获取canvas var chess = document.getElementById('chess'); //获取上下文,创 ...

  3. 阻塞IO, 非阻塞IO, 同步IO,异步IO

    阻塞IO, 非阻塞IO, 同步IO,异步IO 介绍 先说明几个概念 用户空间与内核空间 为了保证用户进程不能直接操作内核(kernel),保证内核的安全,操心系统将虚拟空间(内存)划分为两部分,一部分 ...

  4. MySQL子查询有哪五种形式?

    MySQL是一个关系型数据库管理系统,由瑞典MySQLAB公司开发,目前属于Oracle旗下产品.MySQL是最流行的关系型数据库管理系统之一,在web应用方面,MySQL是最好的RDBMS(Rela ...

  5. R cannot be resolved的几种可能 R not generated

    项目又爆红了,Eclipse真是够操心,顺便看一下R cannot be resolved的几种可能 这次是SVN合并的问题 2015-12-24 主要看 Console 输出的问题位置即可,一般都是 ...

  6. hdu-3015 Disharmony Trees---离散化+两个树状数组

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3015 题目大意: 有一些树,这些树的高度和位置给出.现在高度和位置都按从小到大排序,对应一个新的ra ...

  7. 谷歌Web中文开发手冊:3响应式

    https://developers.google.com/web/fundamentals/getting-started/your-first-multi-screen-site/responsi ...

  8. python 面向对象(一)--类(class)和实例(Instance)

    面向对象最重要的概念就是类(Class)和实例(Instance),必须牢记类是抽象的模板,比如Student类,而实例是根据类创建出来的一个个具体的“对象”,每个对象都拥有相同的方法,但各自的数据可 ...

  9. 问题 D: C++ 习题 输出日期时间--友元函数

    题目描述 设计一个日期类和时间类,编写display函数用于显示日期和时间.要求:display函数作为类外的普通函数,分别在Time和Date类中将display声明为友元函数.在主函数中调用dis ...

  10. 2018.7.5 jQuery学习

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...