zoukankan      html  css  js  c++  java
  • 1017

    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
    ",s,dp[v][n]);
    62         }
    63         return 0;
    64 }
     
    油!油!you@
  • 相关阅读:
    练习10.9-2
    [转]JVM 内存初学 (堆(heap)、栈(stack)和方法区(method) )
    JAVA成员变量为什么不能在类体中先定义后赋值
    core image几个滤镜样例 oc版本号和swift版本号
    UVa 11997 K Smallest Sums 优先队列&amp;&amp;打有序表&amp;&amp;归并
    Android基础新手教程——4.4.1 ContentProvider初探
    Restore IP Addresses -- LeetCode
    Android中Intent传递类对象的方法一(Serializable)
    Effective C++:条款22:将成员变量声明为private
    javascript cookie
  • 原文地址:https://www.cnblogs.com/zzuli2sjy/p/5597943.html
Copyright © 2011-2022 走看看