Alice’s Stamps HDU - 6249 (区间DP)
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
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.
思路:可能存在左端点相同的多个区间,那么此时我们肯定选右端点最大的那个区间。现在将区间按左端点排序,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)的更多相关文章
- hdu 4283 区间dp
You Are the One Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化
HDU 2829 区间DP & 前缀和优化 & 四边形不等式优化 n个节点n-1条线性边,炸掉M条边也就是分为m+1个区间 问你各个区间的总策略值最少的炸法 就题目本身而言,中规中矩的 ...
- HDU 4293---Groups(区间DP)
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4293 Problem Description After the regional con ...
- String painter HDU - 2476 -区间DP
HDU - 2476 思路:分解问题,先考虑从一个空串染色成 B串的最小花费 ,区间DP可以解决这个问题 具体的就是,当 str [ l ] = = str [ r ]时 dp [ L ] [ R ] ...
- HDU 4632 区间DP 取模
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4632 注意到任意一个回文子序列收尾两个字符一定是相同的,于是可以区间dp,用dp[i][j]表示原字 ...
- 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) ...
- HDU 4570(区间dp)
E - Multi-bit Trie Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- hdu 2476 区间dp
题意: 给出两个串s1和s2,一次只能将一个区间刷一次,问最少几次能让s1=s2 例如zzzzzfzzzzz,长度为11,我们就将下标看做0~10 先将0~10刷一次,变成aaaaaaaaaaa 1~ ...
- hdu 4632(区间dp)
Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65535 K (Java/ ...
随机推荐
- Mincost
The cost of taking a taxi in Hangzhou is not a constant for each kilometer you travel: the first 4 k ...
- ARM平台指令虚拟化初探
0x00:什么是代码虚拟化? 虚拟机保护是这几年比较流行的软件保护技术.这个词源于俄罗斯的著名软件保护软件“VmProtect”,以此为开端引起了软件保护壳领域的革命,各大软件保护壳都将虚拟机保护这一 ...
- IIS7 配置SSL 绑定主机头
IIS7下面默认HTTPS绑定是无法指定主机头的,我们可以通过手工修改IIS配置来实现主机头绑定. 首先停止IIS服务. 然后打开C:/Windows/system32/inetsrv/config/ ...
- Quartz .Net(定时框架):
Quartz .Net(定时框架): 基本说明: 说明:Quartz .Net 是一个从 Java 版的 Quartz 移植过来定时任务框架,可以实现异常灵活的定 时任务 用法: 安装 Quartz ...
- 对react vd 性能的理解
相信大家都知道react vd的性能是很好的,速度挺快的,真实dom操作很慢的,但是结果完全相反: 后来我就做了个测试,从两个方面去测试,在页面初始渲染1w条数据,react渲染耗时超过了1秒 在12 ...
- RC4 in TLS is Broken: Now What?
https://community.qualys.com/blogs/securitylabs/2013/03/19/rc4-in-tls-is-broken-now-what RC4 has lon ...
- Windows Python 版本切换工具 --- Switch Python Version Tool For Windows
2018年1月13日 更新: 如果要用到不同版本的Python 请使用 virtualenv, pip install virtualenv , 我做的这个工具可以拿来维护下环境变量~~ 填好路径自 ...
- May 8th 2017 Week 19th Monday
Art lies in concealing art. 隐而不露即艺术. Sometimes, concealing is much more seductive than totally naked ...
- 使用ABAP Push Channel(APC)开发的乒乓球游戏,可双打
url: https://:/sap/bc/apc_test/ping_pong/game 或者事务码SICF, 输入ping_pong, 按F8: 选中搜索结果,点右键选择Test,即可打开url. ...
- CentOS 7与 Windows双系统丢失Windows启动项及默认启动项修改
1.Windows启动项消失的原因: 在安装Win7.8/10系统+CentOS7双系统后,默认会将mbr(Main Boot Record)改写为grub2,默认的CentOS7无法识别Wind ...