LightOJ1017---Brush (III) (dp)
2015-06-08 19:56
435 查看
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
dp[i][j]dp[i][j]前i个点(先排好序,然后处理出每个y坐标上有多少个点)使用j次操作,最多可以扫掉的点
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
dp[i][j]dp[i][j]前i个点(先排好序,然后处理出每个y坐标上有多少个点)使用j次操作,最多可以扫掉的点
/************************************************************************* > File Name: LightOJ1017.cpp > Author: ALex > Mail: zchao1995@gmail.com > Created Time: 2015年06月08日 星期一 19时26分07秒 ************************************************************************/ #include <functional> #include <algorithm> #include <iostream> #include <fstream> #include <cstring> #include <cstdio> #include <cmath> #include <cstdlib> #include <queue> #include <stack> #include <map> #include <bitset> #include <set> #include <vector> using namespace std; const double pi = acos(-1.0); const int inf = 0x3f3f3f3f; const double eps = 1e-15; typedef long long LL; typedef pair <int, int> PLL; map <int, int> st; int dp[110][110]; struct node { int num; int y; }p[110]; int cmp(node a, node b) { return a.y > b.y; } int main() { int t, icase = 1; scanf("%d", &t); while (t--) { st.clear(); int n, w, k; int x, y; scanf("%d%d%d", &n, &w, &k); for (int i = 1; i <= n; ++i) { scanf("%d%d", &x, &y); if (st.find(y) == st.end()) { st[y] = 1; } else { ++st[y]; } } int cnt = 0; for (map <int, int> :: iterator it = st.begin(); it != st.end(); ++it) { p[++cnt].y = it -> first; p[cnt].num = it -> second; } sort(p + 1, p + cnt + 1, cmp); memset(dp, 0, sizeof(dp)); for (int i = 1; i <= cnt; ++i) { for (int j = 1; j <= k; ++j) { dp[i][j] = dp[i - 1][j]; int sum = 0; for (int l = i; l >= 1; --l) { if (p[l].y > p[i].y + w) { break; } sum += p[l].num; dp[i][j] = max(dp[i][j], dp[l - 1][j - 1] + sum); } } } printf("Case %d: %d\n", icase++, dp[cnt][k]); } return 0; }
相关文章推荐
- window.location.href url含中文乱码问题
- Android Studio 常用设置说明
- XML名称空间的解析
- servlet和JSP 对比区别
- 如何构建自己的笔记系统?
- Python相关项目和技术
- 第二阶段冲刺总结
- JAVA中Socket服务器/客户端的通信
- qmake pro文件 生成的makefile文件中包含moc文件依赖项的条件
- 继续firefly,我们来看看as3网游烽烟ol的架设和简单分析
- Windows平台CUDA开发之前的准备工作
- ant 打包android应用
- MIMO-OFDM通信系统学习笔记(一)
- Java知多少(86)文本框和文本区的输入输出
- 计数排序——O(n)复杂度基于非比较的排序方法
- 1.6jdk + eclipse + pydev搭建Python开发环境
- shell脚本循环执行mysql语句
- iOS开发中导入第三方库时不能自动补全头文件的解决方法
- HTML无刷新下载文件方法总汇
- js中获取上下文路径