lightoj 1017 - Brush (III)(dp)

来源:互联网 发布:淘宝订单取消后果严重 编辑:程序博客网 时间:2024/05/01 02:13
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 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


题意:有一把刷子,每次可以横向的刷掉宽度为w的灰尘,现在最多可以刷m次。最多可以刷掉多少灰尘

思路:dp[i][j]表示刷到第i个灰尘用了j次的最多刷灰尘数,首先肯定对灰尘以y坐标排序。对于每个i的,我们可以枚举一个1~i的k,然后k~i的高度差小于等于w的话,k~i就可以一次刷完,这个时候我们就可以得到转移方程:dp[i][k] = max(dp[i][k], dp[j-1][k-1] + cnt),这个cnt就是之间的灰尘数量。

#include<iostream>#include<cstdio>#include<algorithm>#include<map>#include<cstring>#include<map>#include<set>#include<queue>#include<stack>#include<cmath>using namespace std;const double eps = 1e-10;const int inf = 0x3f3f3f3f, N = 1e2 + 10, Mod = 1000000007;typedef long long ll;struct node{    int x, y;} p[N];int cmp(node a, node b){    return a.y < b.y;}int dp[N][N];int main(){    int t;    cin>>t;    for(int cas = 1; cas<=t; cas++)    {        int n, w, m;        scanf("%d%d%d", &n,&w, &m);        for(int i = 1; i<=n; i++)            scanf("%d %d", &p[i].x, &p[i].y);        memset(dp, 0, sizeof(dp));        sort(p+1, p+n+1, cmp);        /*  for(int i = 1; i<=n; i++)              for(int j = 1; j<=i; j++)              {                  if(p[i].y - p[j].y <= w)                  {                      dp[i][1]++;                  }              }              */        for(int i = 1; i<=n; i++)        {            for(int k = 1; k<=m; k++)            {                dp[i][k] += dp[i-1][k];                int cnt = 0;                for(int j = i; j>=1; j--)                {                    if(p[i].y - p[j].y > w)                        break;                    else                    {                        cnt ++;                        dp[i][k] = max(dp[i][k], dp[j-1][k-1] + cnt);                    }                }            }        }        int ans = 0;        for(int i = 1; i<=m; i++)        {            ans = max(dp[n][i], ans);        }        printf("Case %d: %d\n", cas, ans);    }    return 0;}

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 华为v9手机激活密码忘了怎么办 公司报销发票纸质的丢了怎么办 在京东上买的小天才手表坏了怎么办 美亚买东西过几天降价了怎么办 天猫买东西退款后又不想退了怎么办 自己写错了地址快递被签收了怎么办 在天猫购买东西不发货怎么办 在天猫买了东西不给我发货怎么办 天猫退货卖家收到货不退款怎么办 唯品会的账号找不回来了怎么办 从网上买的沙发物流超级慢怎么办 三星c5手机玩王者荣耀卡怎么办 买手机送话费的卡不想用了怎么办 到银行存钱被骗买保险了怎么办 去银行存钱被骗买了保险怎么办 京东申请退款后卖家又发货了怎么办 苹果6s没有4g网怎么办 花呗分期付款买手机额度不够怎么办 手机天猫不支持购买淘宝商品怎么办 天猫国际购买商品狠盾怎么办 在微信上微拍堂买东西被骗了怎么办 京东自营买到返修手机怎么办? 7p弯了怎么办能修复吗 农商银行app登录密码忘了怎么办 网址上的重庆时时彩不能提现怎么办 天天中彩票自己账户登录不了怎么办 天猫上卖王者荣耀的兑换码是怎么办 身份证借别人开淘宝永久封店怎么办 天猫店铺被扣12分怎么办 天猫法人变更之前的天猫贷款怎么办 在日本旅游遇到精日导游怎么办 银行资金交易异常卡被冻结怎么办 如果淘宝被盗了店铺乱上东西怎么办 快递不送货直接代售点签收怎么办 淘宝快递没收到却显示已签收怎么办 支付宝余额未满16受限怎么办 未满16岁支付宝余额受限怎么办 手机天猫购物买的数量大怎么办 扣扣游戏领礼包出现账号异常怎么办 美容院转让给别人客人要退钱怎么办 卖家毁约中介费担保费怎么办