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 |
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 ",s,dp[v][n]); 62 } 63 return 0; 64 }