Kpop Music Party


Time Limit: 2 Seconds      Memory Limit: 65536 KB


Marjar University often hosts Kpop music festival. A Kpop music festival will last several days. During a Kpop festival, there will be a Kpop party every day. Kpop music is very popular
all over the world, so there may be more than one Kpop music festival being hosted simultaneously.

Edward, the headmaster of Marjar University, is always obsessed with Kpop music. He will be very excited continuously for K days after attending a Kpop music party. More specifically,
If he attends a Kpop party in the i-th day, he would be very excited from the i-th day to the (i + K - 1)-th day (inclusive). But the excitatory state does not stack. For example, if K is 5 and Edward
attended a party in Day 1 and a party in Day 3, he will be very excited only from Day 1 to Day 7.

Edward has got the schedule of N Kpop music festivals in Marjar University. Each Kpop music festival lasts one or more days. The i-th Kpop festival starts at the Si-th
day and ends at the Ei-th day (inclusive). Due to restrictions on the discipline for the headmaster, he can attend at most M Kpop parties. Now he wants to maximize the number of days being excited. Can you help him?

Input

There are multiple test cases. The first line of input is an integer T (≤ 1000) indicating the number of test cases. For each test case:

The first line contains three integers, NK and M.

The next N lines, each line contains two integers Si and Ei (1 ≤ N ≤ 10, 1 ≤ KMSiEi ≤
109).

Output

For each case, print the number of the most days that Edward can be excited for.

Sample Input

2
1 5 2
1 3
3 7 3
1 5
2 5
13 13

Sample Output

7

18

这道题目最先想到的是贪心,从最左边开始,依次选择长度k的区间,不相交,这样是最大的。但是这样贪心完之后发现m还有剩余,

发现每个区间的最后一点也可以选,同样可以有增益效果,但是回头再去选,会打乱一开始的贪心,所以在贪心的时候就枚举每个区间

最后一个点要不要选,最后也就2的10次方种可能
#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h> using namespace std;
typedef long long int LL;
struct Node{
LL l,r;
}a[15],b[15];
int cmp(Node a,Node b){
if(a.l==b.l)
return a.r<b.r;
return a.l<b.l;
}
int n1;
LL m,k,res;
int cnt;
void dfs(LL pos,int i,LL ans,LL n){
if(n>m)
return;
if((i>=cnt+1)||n==m){
res=max(res,ans);
return;
}
LL len,pos1,num,p2,p;
if(pos<b[i].r){
len=min(b[i].r-b[i].l+1,b[i].r-pos);
p=len%k;
if(p==0) p2=len/k;
else p2=len/k+1;
if(p2+n>m) res=max(res,ans+(m-n)*k);
pos1=max(b[i].l+p2*k-1,pos+p2*k);
num=p2*k;
dfs(pos1,i+1,ans+num,n+p2);//不选最后一个点
dfs(b[i].r+k-1,i+1,ans+num+b[i].r+k-1-pos1,n+p2+1);//选择最后一个点
}
else if(pos>=b[i].r){
dfs(pos,i+1,ans,n);//不选最后一个点
dfs(b[i].r+k-1,i+1,ans+b[i].r+k-1-pos,n+1);//选择最后一个点
}
}
int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%d%lld%lld",&n1,&k,&m);
for(int i=1;i<=n1;i++)
scanf("%lld%lld",&a[i].l,&a[i].r);
sort(a+1,a+n1+1,cmp);
cnt=0;
int i,j;
for(i=1;i<=n1;i){
for( j=i+1;j<=n1;j++){
if(a[j].l<=a[i].r+1)//区间可以合并
{a[i].r=max(a[i].r,a[j].r);}
else break;
}
b[++cnt]=a[i];
i=j;
}
res=0;
dfs(0,1,0,0);
printf("%lld\n",res);
}
return 0;
}

ZOJ 3941 Kpop Music Party(省赛, 贪心)的更多相关文章

  1. ZOJ 3941 Kpop Music Party 贪心

    题目链接: http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=3941 题解: 先吧所给的区间合并,得到若干个独立的区间. 然后从左 ...

  2. ZOJ 3941 Kpop Music Party

    先把能合并的区间都合并起来. 考虑最裸的贪心策略,从左到右一段一段的取. 但是,这样会有错,错在没有考虑每段区间选取最后一个点. 因为N只有10,所以枚举一下哪些区间最后一个点会被选择,然后按照最裸的 ...

  3. ZOJ 1025 Wooden Sticks(快排+贪心)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=25 题目大意:机器运送n个木条,每个木条有一个长度和重量.运送第一根木 ...

  4. ZOJ 3872 浙江2015年省赛试题

    D - Beauty of Array Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu S ...

  5. ZOJ 2819 Average Score 牡丹江现场赛A题 水题/签到题

    ZOJ 2819 Average Score Time Limit: 2 Sec  Memory Limit: 60 MB 题目连接 http://acm.zju.edu.cn/onlinejudge ...

  6. [NOIP模拟赛][贪心]奶牛晒衣服.

    奶牛晒衣服(dry) [问题描述] 在熊大妈英明的带领下,时针和它的同伴生下了许多牛宝宝.熊大妈决定给每个宝宝都穿上可爱的婴儿装.于是,为牛宝宝洗晒衣服就成了很不爽的事情. 圣人王担负起了这个重任.洗 ...

  7. ZOJ - 4019 Schrödinger's Knapsack (背包,贪心,动态规划)

    [传送门]http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5747 [题目大意]:薛定谔的背包.薛定谔的猫是只有观测了才知道猫的死 ...

  8. HDU 6438 Buy and Resell ( 2018 CCPC 网络赛 && 贪心 )

    题目链接 题意 : 给出一些数.你可以从左到右对这些数进行三种操作花费 Ai 买入东西.以 Ai 价格卖出你当前有的东西.或者什么都不做.现在问你可以获取的最大利益是多少? 分析 : 和 CF 867 ...

  9. hdu6438 Buy and Resell 买卖物品 ccpc网络赛 贪心

    题目传送门 题目描述: 有n座城市,每座城市都可以对一个物品进行一次的买进或者卖出,可以同时拥有多个物品,计算利润最大值,并且交易次数要最少.(买入卖出算两次操作) 思路: 建立两个小根堆 优先队列, ...

随机推荐

  1. 一个官翻教程集合:ASP.NET Core 和 EF Core 系列教程

    通过一个大学课程案例讲解了复杂实体的创建过程及讲解 1.ASP.NET Core 和 Entity Framework Core 系列教程——入门 (1 / 10) 2.ASP.NET Core 和 ...

  2. FIFO、LRU、OPT页面调度算法及样例

    网上非常多介绍3种页面置换算法的样例和过程是不对的, 本文依据<操作系统概念>第七版对三种算法做介绍,并给出正确的样例以验证算法. 一.FIFO先进先出页面置换算法,创建一个FIFO队列来 ...

  3. PT100三线制恒流源接法

    http://www.eepw.com.cn/article/189480_2.htm 下图为恒流源激励的三线制Pt100的一种典型接法.其基本原理是假设Pt100的三条引线采用相同长度的同型线缆,具 ...

  4. AngularJS体验式编程系列文章

    AngularJS体验式编程系列文章,将介绍如何用angularjs构建一个强大的web前端系统.angularjs是由Google团队开发的一款非常优秀web前端框架.在当前如此多的web框架下,a ...

  5. atitit. it软件项目管理---自己的员工,雇佣军、援军,混合的员工 杂牌 人员管理架构

    atitit. it软件项目管理---自己的员工,雇佣军.援军,混合的员工 杂牌 人员管理架构 1. 企业的正规军,雇佣军,杂牌划分 1 1.1. 企业的员工基本是雇佣而来 1 1.2. 全职员工与兼 ...

  6. 让 Vivado有Zybo Board的配置文件

    Zybo Board开发记录: 让 Vivado有Zybo Board的配置文件 由 judyzhong 于 星期三, 07/13/2016 - 10:41 发表 本文转载自:coldnew's bl ...

  7. shader 笔记(一)

  8. 初识PowerShell

    一.简介 Windows PowerShell 是微软公司为Windows环境所开发的壳程序(shell)及脚本语言技术,采用的是命令行界面.这项全新的技术提供了丰富的控制与自动化的系统管理能力.之前 ...

  9. 使用java语言如何更好的使用多线程?

    ① 高并发.任务执行时间短的业务,线程池线程数可以设置为CPU核数+1,减少线程上下文的切换. ② 并发不高.任务执行时间长的业务要区分开看: 假如是业务时间长集中在I/O操作上,也就是I/O密集型的 ...

  10. mysql乐观锁和悲观锁

    在多用户环境中,在同一时间可能会有多个用户更新相同的记录,这会产生冲突.这就是著名的并发性问题. 悲观锁:假定会发生并发冲突,屏蔽一切可能违反数据完整性的操作. 乐观锁:假设不会发生并发冲突,只在提交 ...