1017 - Brush (III)
2016-06-19 13:38
134 查看
1017 - Brush (III)
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.
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.
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];
PDF (English) | Statistics | Forum |
Time Limit: 2 second(s) | Memory Limit: 32 MB |
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 |
题意:给你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];
#include<stdio.h> #include<algorithm> #include<iostream> #include<string.h> #include<stdlib.h> #include<math.h> #include<queue> #include<stack> #include<vector> using namespace std; typedef long long LL; typedef struct pp { int x; int y; } ss; ss ans[200]; bool cmp(pp p,pp q) { return p.y<q.y; } int dp[200][10005]; vector<int>vec[200]; bool flag[300]; int ak[300]; int main(void) { int i,j,k; scanf("%d",&k); int s; int n,m,v; for(s=1; s<=k; s++) { scanf("%d %d %d",&n,&m,&v); memset(flag,0,sizeof(flag)); memset(ak,0,sizeof(ak)); for(i=0; i<n; i++) { scanf("%d %d",&ans[i].x,&ans[i].y); } sort(ans,ans+n,cmp); memset(dp,0,sizeof(dp)); for(i=0; i<n; i++) { for(j=i; j>=0; j--) { if(ans[i].y-ans[j].y>m) break; ak[i]++; } } int maxx=0; for(j=1; j<=v; j++) { for(i=1; i<=n; i++) { int uu=dp[j-1][i-ak[i-1]]+ak[i-1]; dp[j][i]=max(dp[j][i-1],uu); } } printf("Case %d: %d\n",s,dp[v] ); } return 0; }
相关文章推荐
- 如何使用树莓派CPU挖矿(没有测试成功)
- Multinomial Logistic Regression
- css3基础、(弹性、响应式)布局注意点
- 80老翁谈人生(6):一生追梦的历程
- 系统中的插件和控件
- 美丽的图案
- 中间件技术的思想、概念和分类
- solve SetDefaultDllDirectories’ : is not a member of ‘`global namespace” from line 638 in atlcore.h
- ES6中的Promise相关知识简述
- Win 10 开启SQL server 失败
- extern "C" _declspec(dllexport)浅析
- mysql中插入中文报错怎么解决
- Linux设置学习登录系统每日一命令提示
- popupWindow
- 数据库使用疑难汇总
- chrome 浏览器的预提取资源机制导致的一个请求发送两次的问题以及ClientAbortException异常
- centos安装mysql5.7
- Android第一行代码知识总结(1)
- Python中使用help查看某一类对象的内置方法
- 马哥教育网络班+第二周课程练习