1017 - Brush (III)
Time Limit: 2 second(s) Memory Limit: 32 MB

Samir returned home from the contest and got angry after seeing his room dusty. Who likes to see a dusty room after a brain storming programming contest? After checking a bit he found a brush in his room which has width w. Dusts are defined as 2D points. And since they are scattered everywhere, Samir is a bit confused what to do. He asked Samee and found his idea. So, he attached a rope with the brush such that it can be moved horizontally (in X axis) with the help of the rope but in straight line. He places it anywhere and moves it. For example, the y co-ordinate of the bottom part of the brush is 2 and its width is 3, so the y coordinate of the upper side of the brush will be 5. And if the brush is moved, all dusts whose y co-ordinates are between 2 and 5 (inclusive) will be cleaned. After cleaning all the dusts in that part, Samir places the brush in another place and uses the same procedure. He defined a move as placing the brush in a place and cleaning all the dusts in the horizontal zone of the brush.

You can assume that the rope is sufficiently large. Since Samir is too lazy, he doesn't want to clean all the room. Instead of doing it he thought that he would use at most k moves. Now he wants to find the maximum number of dust units he can clean using at most k moves. Please help him.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a blank line. The next line contains three integers N (1 ≤ N ≤ 100), w (1 ≤ w ≤ 10000) and k (1 ≤ k ≤ 100). N means that there are N dust points. Each of the next N lines contains two integers: xi yi denoting the coordinates of the dusts. You can assume that (-109 ≤ xi, yi ≤ 109) and all points are distinct.

Output

For each case print the case number and the maximum number of dusts Samir can clean using at most k moves.

Sample Input

Output for Sample Input

2

3 2 1

0 0

20 2

30 2

3 1 1

0 0

20 2

30 2

Case 1: 3

Case 2: 2


Problem Setter: Jane Alam Jan
题意:给你n个点,然后给你刷子的宽度,然后给你刷的次数k,并且刷子只能够平行与x轴刷,问你刷k次最多能刷多少个点;
思路:肯定与x无关,所以我们按照y从小到大排序,一开始我想用贪心,发现不对,后来发现是个dp;
dp[i][j]表示当前j个点刷了j次最多能刷多少个。
状态转移方程:dp[i][j]=max(dp[i][j-1],dp[i-1][j-cnt[j]]+cnt[j]);
cnt[j]表示当刷这个点时向前能刷到的点,那么当第i次刷时可以选择刷或不刷第j个点,刷为dp[i-1][j-cnt[j]]+cnt[j],不刷为dp[i][j-1];
 1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<stdlib.h>
6 #include<math.h>
7 #include<queue>
8 #include<stack>
9 #include<vector>
10 using namespace std;
11 typedef long long LL;
12 typedef struct pp
13 {
14 int x;
15 int y;
16 } ss;
17 ss ans[200];
18 bool cmp(pp p,pp q)
19 {
20 return p.y<q.y;
21 }
22 int dp[200][10005];
23 vector<int>vec[200];
24 bool flag[300];
25 int ak[300];
26 int main(void)
27 {
28 int i,j,k;
29 scanf("%d",&k);
30 int s;
31 int n,m,v;
32 for(s=1; s<=k; s++)
33 {
34 scanf("%d %d %d",&n,&m,&v);
35 memset(flag,0,sizeof(flag));
36 memset(ak,0,sizeof(ak));
37 for(i=0; i<n; i++)
38 {
39 scanf("%d %d",&ans[i].x,&ans[i].y);
40 }
41 sort(ans,ans+n,cmp);
42 memset(dp,0,sizeof(dp));
43 for(i=0; i<n; i++)
44 {
45 for(j=i; j>=0; j--)
46 {
47 if(ans[i].y-ans[j].y>m)
48 break;
49 ak[i]++;
50 }
51 }
52 int maxx=0;
53 for(j=1; j<=v; j++)
54 {
55 for(i=1; i<=n; i++)
56 {
57 int uu=dp[j-1][i-ak[i-1]]+ak[i-1];
58 dp[j][i]=max(dp[j][i-1],uu);
59 }
60 }
61 printf("Case %d: %d\n",s,dp[v][n]);
62 }
63 return 0;
64 }
 

1017 - Brush (III)的更多相关文章

  1. Lightoj 1017 - Brush (III)

    1017 - Brush (III)    PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Sam ...

  2. lightOJ 1017 Brush (III) DP

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1017 搞了一个下午才弄出来,,,,, 还是线性DP做的不够啊 看过数据量就知道 ...

  3. LightOJ 1017 - Brush (III) 记忆化搜索+细节

    http://www.lightoj.com/volume_showproblem.php?problem=1017 题意:给出刷子的宽和最多横扫次数,问被扫除最多的点是多少个. 思路:状态设计DP[ ...

  4. Light OJ 1017 - Brush (III)

    题目大意:     在一个二维平面上有N个点,散落在这个平面上.现在要清理这些点.有一个刷子刷子的宽度是w. 刷子上连着一根绳子,刷子可以水平的移动(在X轴方向上).他可以把刷子放在任何一个地方然后开 ...

  5. Brush (III) LightOJ - 1017

    Brush (III) LightOJ - 1017 题意:有一些点,每刷一次可以将纵坐标在区间(y1,y1+w)范围内的所有点刷光,y1为任何实数.最多能刷k次,求最多共能刷掉几个点. 先将点按照纵 ...

  6. LightOJ1017 Brush (III)(DP)

    题目大概说一个平面上分布n个灰尘,现在要用一个宽w的刷子清理灰尘:选择一个起点,往水平线上扫过去这个水平线上的灰尘就消失了.问最多进行k次这样的操作能清理最多多少灰尘. 没什么的DP. 先按垂直坐标给 ...

  7. lightoj刷题日记

    提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...

  8. dp百题大过关(第一场)

    好吧,这名字真是让我想起了某段被某教科书支配的历史.....各种DP题层出不穷,不过终于做完了orz 虽然各种手糊加乱搞,但还是要总结一下. T1 Monkey Banana Problem    这 ...

  9. 【转】c#、wpf 字符串,color,brush之间的转换

    转自:http://www.cnblogs.com/wj-love/archive/2012/09/14/2685281.html 1,将#3C3C3C 赋给background this.selec ...

随机推荐

  1. fastboot烧写Andriod 以及SD 卡烧写LinuxQT,

    EMMC是一种FLASH,SD(TF)卡是另外的一种存储,通过控制拨码开关指引CPU去读EMMC还是SD卡的u-boot文件. u-boot的作用 初始化内存控制区,访问存储器,把内核从存储器读取出来 ...

  2. 零基础学习java------26--------获取省访问量的top3,APP版本数据分析,事务,json,json字符串与对象间的相互转换,求电影平均分

    一. day23中的ip,url案例(前面答案错了) 思路分析: 1.创建javabean,用来存储ip.txt各字段的信息 2. 创建java工具类,封装相应的方法 (1) 加载读取ip.txt文档 ...

  3. Express中间件原理详解

    前言 Express和Koa是目前最主流的基于node的web开发框架,他们的开发者是同一班人马.貌似现在Koa更加流行,但是仍然有大量的项目在使用Express,所以我想通过这篇文章说说Expres ...

  4. 使用Rapidxml重建xml树

    需求 : 重建一棵xml树, 在重建过程中对原来的标签进行一定的修改. 具体修改部分就不给出了, 这里只提供重建部分的代码 code : /****************************** ...

  5. 【分布式】Zookeeper客户端基本的使用

    与mysql.redis等软件一样,zookeeper的软件包中也提供了客户端程序用于对服务器上的数据进行操作.本节我们就来学习zookeeper客户端的使用方法.不过在详细讲解zk客户端的使用方法之 ...

  6. 【Linux】【Shell】【text】sed

        sed [OPTION]...  'script'  [input-file] ...         script:             地址定界编辑命令                 ...

  7. 应用层协议——DHCP

    常见协议分层 网洛层协议:包括:IP协议.ICMP协议.ARP协议.RARP协议. 传输层协议:TCP协议.UDP协议. 应用层协议:FTP.Telnet.SMTP.HTTP.RIP.NFS.DNS ...

  8. linux基础-TCP/IP协议篇

    一.网络TCP/IP层次模型 1.网络层次模型概念介绍:TCP/IP协议就是用于简化OSI层次,以及相关的标准.传输控制协议(tcp/ip)族是相关国防部(DoD)所创建的,主要用来确保数据的完整性及 ...

  9. maven依赖对zookeeper的版本冲突问题

    我用的是springcloudAlibaba+zookeeper zookeeper下载后 1,修改配置文件,conf目录下的zoo_sample.cfg修改为zoo.cfg. 2,打开zoo.cfg ...

  10. IIS 发布 WebService 连接DB2数据库报错如下图

    环境描述: 系统环境: Windows Server 2012 R2      IIS版本:IIS 6.2      C#环境:.NET Framework 4  DB2版本:9.7.500.702 ...