HDU-6249:Alice’s Stamps(DP)
来源:互联网 发布:nginx 密码 编辑:程序博客网 时间:2024/06/03 13:50
Alice’s Stamps
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 332 Accepted Submission(s): 107
Problem Description
Alice likes to collect stamps. She is now at the post office buying some new stamps.
There areN 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 mostK different sets. What is the maximum number of different kinds of stamps that Alice can get?
There are
All of the sets cost the same amount; because Alice has a limited budget, she can buy at most
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 ithoftheselinesrepresentsthe i^{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
Each test case begins with a line containing three integers:
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
25 3 23 41 11 3100 2 11 5090 100
Sample Output
Case #1: 4Case #2: 50HintIn sample case #1, Alice could buy the first and the third stamp sets, which contain the first four kindsof stamp. Note that she gets two copies of stamp 3, but only the number of different kinds of stampsmatters, 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个set能得到的不同的邮票的最大值。
#include<bits/stdc++.h>using namespace std;int d[3000][3000],up[3000];int main(){ int T,cas=1,n,m,num;cin>>T; while(T--) { scanf("%d%d%d",&n,&m,&num); memset(up,0,sizeof up); memset(d,0,sizeof d); for(int i=1,x,y;i<=m;i++) { scanf("%d%d",&x,&y); for(int j=x;j<=y;j++)up[j]=max(up[j],y); } for(int i=1;i<=n;i++) { for(int j=0;j<num;j++) { d[i][j+1]=max(d[i][j+1],d[i-1][j+1]); d[i][j]=max(d[i][j],d[i-1][j]); if(up[i])d[up[i]][j+1]=max(d[up[i]][j+1],d[i-1][j]+up[i]-i+1); } } printf("Case #%d: %d\n",cas++,d[n][num]); } return 0;}
阅读全文
1 0
- HDU-6249:Alice’s Stamps(DP)
- hdu 6249 Alice’s Stamps [DP]
- HDU-6249-Alice’s Stamps
- hdu - 3660 - Alice and Bob's Trip(树形dp)
- hdu 4791 Alice's Print Service (DP+离线处理)
- 文章标题 HDU 4791 :Alice's Print Service(二分+dp)
- [HDU] 3660 Alice and Bob's Trip -- 树形DP?
- 树形dp-hdu-3660-Alice and Bob's Trip
- hdu 3660 Alice and Bob's Trip(树形DP)
- HDU 4791 Alice's Print Service 简单DP
- USACO / Stamps(DP)
- hdoj 3660 Alice and Bob's Trip(树dp)
- uva 1484 Alice and Bob's Trip (树形dp)
- UVALive 5088 Alice and Bob's Trip(树形DP)
- UVA 1484 - Alice and Bob's Trip(树形DP)
- uva 1484 - Alice and Bob's Trip(树形dp)
- UVA1484 Alice and Bob's Trip(树形dp)
- UVALive 5088 Alice and Bob's Trip(树形DP)
- 面向对象:寻找一颗相知相疼的心
- Ubuntu git的安装配置使用
- 谷歌 AI 中国中心正式成立,李飞飞李佳领衔
- 漫画解读:通过造汽车了解软件开发模式
- 是呀,我就是首批依然没过30岁的90后佛系程序员
- HDU-6249:Alice’s Stamps(DP)
- java二叉树
- git工具常用命令
- 谨以此纪念终将逝去的TYVJ
- C# winform ListView 鼠标经过数据行高亮
- SpringMVC-mybatis参数绑定
- Redis中的List类型与消息队列的不同之处。
- 给定一个数组和滑动窗口的大小,找出所有滑动窗口里数值的最大值。例如,如果输入数组{2,3,4,2,6,2,5,1}及滑动窗口的大小3,那么一共存在6个滑动窗口,他们的最大值分别为{4,4,6,6,6,
- [BZOJ3530]-[Sdoi2014]数数-AC自动机+数位DP