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 }
 

最新文章

  1. mac 查看无线wifi的密码
  2. java_method_数据去重
  3. linux, configure --prefix=/有什么用
  4. Sql 中text类型字段判断是否为空
  5. 注意力机制(Attention Mechanism)在自然语言处理中的应用
  6. jquery $(this).attr $(this).val方法使用介绍--useful
  7. lab3
  8. WCF:System.Security.Cryptography.CryptographicException: 密钥集不存在
  9. 多条件搜索拼接Sql语句
  10. UC编程:通过fwrite()和write()比较标准库函数和系统调用的速度
  11. 多线程进阶之并发工具类:CountDownLatch、CyclicBarrier
  12. 实现excel导入导出功能,excel导入数据到页面中,页面数据导出生成excel文件
  13. Ajax 长轮询
  14. Go Example--panic
  15. python3+虹软2.0 离线人脸识别 demo
  16. 前端js上传文件插件
  17. spring security 配置xml 参考
  18. IntelliJ IDEA 2017版 编译器使用学习笔记(一) (图文详尽版);IDE快捷键使用;IDE多行代码同时编写
  19. 关于 DjangoUeditor 上传图片图片失败,csrf token missing or incorrect 的解决办法
  20. HDU 2050:折线分割平面

热门文章

  1. 学习java 7.22
  2. 浏览器相关,关于强缓存、协商缓存、CDN缓存。
  3. jQuery无限载入瀑布流 【转载】
  4. win10产品密钥 win10永久激活密钥(可激活win10所有版本)
  5. Attempt to invoke virtual method &#39;boolean java.lang.String.equals(java.lang.Object)&#39; on a null objec
  6. list通过比较器进行排序
  7. Dubbo使用Zookeeper注册中心
  8. 【Spring Framework】Spring入门教程(五)AOP思想和动态代理
  9. Spring Boot的异步任务、定时任务和邮件任务
  10. 【C/C++】指针,传参,引用的一些个人理解。