LightOJ1017 Brush (III)(DP)
题目大概说一个平面上分布n个灰尘,现在要用一个宽w的刷子清理灰尘:选择一个起点,往水平线上扫过去这个水平线上的灰尘就消失了。问最多进行k次这样的操作能清理最多多少灰尘。
没什么的DP。
- 先按垂直坐标给灰尘们排个序,
 - 然后d[i][k]表示前i个灰尘中,进行到第k次清理操作时刷子底部在第i个灰尘的竖坐标能清理的最多灰尘,
 - 最后转移一个一个往前枚举就OK了,规模很小。
 
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int d[][];
int main(){
int t,n,w,K,x[],y;
scanf("%d",&t);
for(int cse=; cse<=t; ++cse){
scanf("%d%d%d",&n,&w,&K);
for(int i=; i<n; ++i){
scanf("%d%d",&y,x+i);
}
sort(x,x+n);
memset(d,,sizeof(d));
d[][]=;
int res=;
for(int i=; i<n; ++i){
int cnt=;
for(int k=; k<i; ++k){
if(x[i]-x[k]<=w){
++cnt;
}
}
d[i][]=cnt;
res=max(res,d[i][]);
for(int j=; j<=K; ++j){
int mx=;
for(int k=; k<i; ++k){
if(x[i]-x[k]<=w){
break;
}
mx=max(mx,d[k][j-]);
}
if(mx!=){
d[i][j]=mx+d[i][];
res=max(res,d[i][j]);
}
}
}
printf("Case %d: %d\n",cse,res);
}
return ;
}
LightOJ1017 Brush (III)(DP)的更多相关文章
- ZOJ 3769-Diablo III(DP)
		
描述 Diablo III is an action role-playing video game. A few days ago, Reaper of Souls (ROS), the new e ...
 - Leetcode之动态规划(DP)专题-123. 买卖股票的最佳时机 III(Best Time to Buy and Sell Stock III)
		
Leetcode之动态规划(DP)专题-123. 买卖股票的最佳时机 III(Best Time to Buy and Sell Stock III) 股票问题: 121. 买卖股票的最佳时机 122 ...
 - Leetcode之动态规划(DP)专题-121. 买卖股票的最佳时机(Best Time to Buy and Sell Stock)
		
Leetcode之动态规划(DP)专题-121. 买卖股票的最佳时机(Best Time to Buy and Sell Stock) 股票问题: 121. 买卖股票的最佳时机 122. 买卖股票的最 ...
 - Leetcode之动态规划(DP)专题-122. 买卖股票的最佳时机 II(Best Time to Buy and Sell Stock II)
		
Leetcode之动态规划(DP)专题-122. 买卖股票的最佳时机 II(Best Time to Buy and Sell Stock II) 股票问题: 121. 买卖股票的最佳时机 122. ...
 - Leetcode之动态规划(DP)专题-188. 买卖股票的最佳时机 IV(Best Time to Buy and Sell Stock IV)
		
Leetcode之动态规划(DP)专题-188. 买卖股票的最佳时机 IV(Best Time to Buy and Sell Stock IV) 股票问题: 121. 买卖股票的最佳时机 122. ...
 - Leetcode之动态规划(DP)专题-309. 最佳买卖股票时机含冷冻期(Best Time to Buy and Sell Stock with Cooldown)
		
Leetcode之动态规划(DP)专题-309. 最佳买卖股票时机含冷冻期(Best Time to Buy and Sell Stock with Cooldown) 股票问题: 121. 买卖股票 ...
 - Leetcode之动态规划(DP)专题-714. 买卖股票的最佳时机含手续费(Best Time to Buy and Sell Stock with Transaction Fee)
		
Leetcode之动态规划(DP)专题-714. 买卖股票的最佳时机含手续费(Best Time to Buy and Sell Stock with Transaction Fee) 股票问题: 1 ...
 - LightOJ 1033  Generating Palindromes(dp)
		
LightOJ 1033 Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
 - lightOJ 1047   Neighbor House (DP)
		
lightOJ 1047 Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...
 
随机推荐
- function与感叹号
			
原文链接:https://swordair.com/function-and-exclamation-mark/ 最近有空可以让我静下心来看看各种代码,function与感叹号的频繁出现,让我回想起2 ...
 - JavaScript数组排序
			
JavaScript的sort方法排序是有问题的,我们可以给sort方法传一个参数 function Compare(value1, value2) { //数字排序的函数参数 if (value1 ...
 - python基础——单元测试
			
python基础——单元测试 如果你听说过“测试驱动开发”(TDD:Test-Driven Development),单元测试就不陌生. 单元测试是用来对一个模块.一个函数或者一个类来进行正确性检验的 ...
 - python基础——使用元类
			
python基础——使用元类 type() 动态语言和静态语言最大的不同,就是函数和类的定义,不是编译时定义的,而是运行时动态创建的. 比方说我们要定义一个Hello的class,就写一个hello. ...
 - Mysql复制之路由
			
在主从复制读写分离的思路下,要想使所有写都到MasterServer,所有读都路由到Slave Server;就需要使用一些路由策略. 可以使用MysqlProxy[Mysql代理],据说MysqlP ...
 - java的system.arraycopy()方法
			
java.lang.System的静态方法arraycopy()可以实现数组的复制,讲课的老师说这个方法效率比较高,如果数组有成千上万个元素,那么用这个方法,比用for语句循环快不少.于是我试了试,发 ...
 - hdu 1279 验证角谷猜想
			
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1279 #include<stdlib.h> #include<time.h> ...
 - Python 文件处理
			
文件夹: 得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd() 返回指定目录下的所有文件和目录名:os.listdir() 函数用来删除一个文件:os.remove() 删 ...
 - htop 源码安装
			
htop-1.0.2.tar.gz http://pan.baidu.com/s/1c1RbdIg tar -xvf htop-1.0.2.tar.gz cd htop-1.0.2 ./config ...
 - jQuery - 4.简单选择器
			
4.1 简单选择器 (1) :first 选取第一个元素. (2) :last 选取最后一个元素. (3) :not(选择器) 选取不满足"选择器"条件的元素 (4) ...