lightoj 1017 - Brush (III)

来源:互联网 发布:访问nginx 服务器 编辑:程序博客网 时间:2024/05/14 08:14

题目链接:http://lightoj.com/volume_showproblem.php?problem=1017


                                                                                          1017 - Brush (III)

PDF (English)StatisticsForum
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 widthw. 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 (inX axis) with the help of the rope but in straight line. He places it anywhere and moves it. For example, they co-ordinate of the bottom part of the brush is 2 and its width is 3, so they coordinate of the upper side of the brush will be 5. And if the brush is moved, all dusts whosey 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 amove 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 mostk moves. Now he wants to find the maximum number of dust units he can clean using at mostk 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 integersN (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 mostk moves.

Sample Input                                                                   

2

 

3 2 1

0 0

20 2

30 2

 

3 1 1

0 0

20 2

30 2

Sample Output

Case 1: 3

Case 2: 2


题意:我是一个粉刷匠,粉刷本领强,我要把那小房子,刷的更漂亮!!!吐舌头吐舌头吐舌头Samir回家当起了粉刷匠,因为家里灰尘太多了

     现在有n个灰尘,给出所在坐标,已知宽度为 w 的粉刷能够横着随便刷,可是她实在太懒了,上下移动就只想动 k 次,求移动 k次最多能除去灰尘多少


思路: 题目只对y坐标有要求,将Y进行从大到小的排序,粉刷顶部刚好碰到最高的灰尘,然后往下刷,一次就能擦去 w 宽范围内的灰尘

    

状态转移方程:dp[i][j]=max(dp[i-1][j],dp[i-move[i]][j-1]+move[i]),前一项表示不擦点i,后一项表示把它和它会影响的点都擦掉。



代码如下:

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int x,y[105],move[105],dp[105][105]; int cmp(int a,int b){return a>=b;}int main (){  int t,n,w,k,i,j,ans=1;scanf("%d",&t);while(t--){       memset(dp,0,sizeof(dp));memset(move,0,sizeof(move));scanf("%d%d%d",&n,&w,&k);for (i=0;i<n;i++)scanf("%d%d",&x,&y[i]);  //Y进行处理 sort(y,y+n,cmp);   //y从高到低进行排序 for (i=0;i<n;i++)  {int high=i,low=i;while (y[high]-y[low]<=w && high>=0)high--;move[i]=low-high;         //move[i]为移动一次擦去的点的个数  }for (i=0;i<n;i++)      for (j=1;j<=k;j++)  //j为移动次数限制    {  if (i>=move[i])  //还有点未擦 dp[i][j]=max(dp[i-1][j],dp[i-move[i]][j-1]+move[i]);//不擦i,擦i  else                                  dp[i][j]=move[i];   }printf("Case %d: %d\n",ans++,dp[n-1][k]);}return 0;} 

 





























0 0
原创粉丝点击