【POJ 2029】 Get Many Persimmon Trees(DP)

PrimeTime生成.lib竟暗藏PG添加Bug 1. 确认原始库中是否包含PG引脚的定义。2. 查阅PrimeTime的write_lib命令文档,寻找相关选项。3. 在生成库时使用正确的选项,例如-include_pg_pins或类似参数。4. 验证生成的.lib文件是否包含pg_pin部分。 阅读详情

【POJ 2029】 Get Many Persimmon Trees(DP)

Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 4024 Accepted: 2628

Description

Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in education, Katanobu Matsudaira, the lord of the domain of Aizu, had decided to grant him a rectangular estate within a large field in the Aizu Basin. Although the size (width and height) of the estate was strictly specified by the lord, he was allowed to choose any location for the estate in the field. Inside the field which had also a rectangular shape, many Japanese persimmon trees, whose fruit was one of the famous products of the Aizu region known as 'Mishirazu Persimmon', were planted. Since persimmon was Hayashi's favorite fruit, he wanted to have as many persimmon trees as possible in the estate given by the lord.
For example, in Figure 1, the entire field is a rectangular grid whose width and height are 10 and 8 respectively. Each asterisk (*) represents a place of a persimmon tree. If the specified width and height of the estate are 4 and 3 respectively, the area surrounded by the solid line contains the most persimmon trees. Similarly, if the estate's width is 6 and its height is 4, the area surrounded by the dashed line has the most, and if the estate's width and height are 3 and 4 respectively, the area surrounded by the dotted line contains the most persimmon trees. Note that the width and height cannot be swapped; the sizes 4 by 3 and 3 by 4 are different, as shown in Figure 1.

Figure 1: Examples of Rectangular Estates

Your task is to find the estate of a given size (width and height) that contains the largest number of persimmon trees.

Input

The input consists of multiple data sets. Each data set is given in the following format.

N
W H
x1 y1
x2 y2
...
xN yN
S T

N is the number of persimmon trees, which is a positive integer less than 500. W and H are the width and the height of the entire field respectively. You can assume that both W and H are positive integers whose values are less than 100. For each i (1 <= i <= N), xi and yi are coordinates of the i-th persimmon tree in the grid. Note that the origin of each coordinate is 1. You can assume that 1 <= xi <= W and 1 <= yi <= H, and no two trees have the same positions. But you should not assume that the persimmon trees are sorted in some order according to their positions. Lastly, S and T are positive integers of the width and height respectively of the estate given by the lord. You can also assume that 1 <= S <= W and 1 <= T <= H.

The end of the input is indicated by a line that solely contains a zero.

Output

For each data set, you are requested to print one line containing the maximum possible number of persimmon trees that can be included in an estate of the given size.

Sample Input

16
10 8
2 2
2 5
2 7
3 3
3 8
4 2
4 5
4 8
6 4
6 7
7 5
7 8
8 1
8 4
9 6
10 3
4 3
8
6 4
1 2
2 1
2 4
3 4
4 2
5 3
6 1
6 2
3 2
0

Sample Output

4
3


题目大意:有一个W*H的田野,里面有n棵树。

现在想用s*t的矩形篱笆圈出尽量多的树,问最多能圈出几棵树?


做法是遍历的过程中记录有用的数据,然后进行dp。

用一个数组记录单行长为t的累加和,这样每个新矩形可以由上一个矩形减一排加一排得到。

这些在遍历过程中进行即可


代码如下:

#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
#include <map>
#include <set>
#define LL long long
#define Pr pair<int,int>
#define fread() freopen("in.in","r",stdin)
#define fwrite() freopen("out.out","w",stdout)

using namespace std;
const int INF = 0x3f3f3f3f;
const int msz = 10000;
const int mod = 1e9+7;
const double eps = 1e-8;

int dp[111][111];
int mp[111][111];
int tmp[111][111];

int main()
{
	//fread();
	//fwrite();

	int n,w,h,s,t,x,y;
	while(~scanf("%d",&n) && n)
	{
		scanf("%d%d",&w,&h);
		memset(mp,0,sizeof(mp));

		while(n--)
		{
			scanf("%d%d",&x,&y);
			mp[x][y] = 1;
		}

		scanf("%d%d",&s,&t);
		memset(dp,0,sizeof(dp));
		memset(tmp,0,sizeof(tmp));

		for(int i = 1; i <= w; ++i)
			for(int j = 1; j <= h; ++j)
			{
				//printf("%d %d:\n",i,j);
				x = i < s? 1: i-s+1;
				y = j < t? 1: j-t+1;

				if(j <= t) tmp[i][y] += mp[i][j];
				else tmp[i][y] = tmp[i][y-1]-mp[i][y-1]+mp[i][j];
				
				if(j >= t) 
				{
					if(i <= s) dp[x][y] += tmp[i][y];
					else dp[x][y] = dp[x-1][y]-tmp[x-1][y]+tmp[i][y];
				}

				//printf("dp[%d][%d] = %d\n",x,y,dp[x][y]);
				//printf("tmp[%d][%d] = %d\n",i,y,tmp[i][y]);
			}

		int mx = 0;
		for(int i = 1; i <= w; ++i)
			for(int j = 1; j <= h; ++j)
				mx = max(mx,dp[i][j]);
		printf("%d\n",mx);
	}

	return 0;
}







EG2134驱动芯片实战:如何用TSSOP20封装搞定三相无刷电机驱动(附电路图) 本文详细介绍了EG2134驱动芯片在三相无刷电机驱动中的应用实践,包括芯片选型、电路设计和PCB布局技巧。EG2134作为一款高性能半桥驱动芯片,采用TSSOP20封装,适合紧凑型设计。文章还提供了典型应用电路图和调试指南,帮助工程师快速实现稳定可靠的电机驱动方案。 阅读详情

相关推荐

vscode远程连接deepin出错:过程试图写入的管道不存在的解决方法

背景:昨天我用vscode使用ssh远程开发还处于正常状态,今天刚打开电脑,并启动deepin,再次使用vscode重新连接就出现异常。意思就是22号默认端口连接被拒绝,所以要先确定ssh是否连接。3.重新进入vscode里面,重新连接,如图成功连接。,查看port后面的端口号是不是22号。1.检查sshd是否启动。

qq_43573047的博客 2953

[POJ - 2029] Get Many Persimmon Trees (二维树状数组)

链接 http://poj.org/problem?id=2029 题意 给你一个W×HW\times HW×H的公园,告诉你这个公园里栽有nnn棵柿子树,并且告诉你这nnn个柿子树的坐标,现在问你大小为s×ts\times ts×t的土地上最多有多少棵柿子树; 分析   二维线段树,把一维的树状数组,及插入函数insertinsertinsert和求和函数sumsumsum均变成二维即可,每告...

梧桐 277

BSW: Dcm模块配置--28服务

这个章节讲解下UDS中的28服务(Communcation Control)的配置,顾名思义,对当前ECU的通讯状态进行变更,主要设置应用报文,网络管理报文的收发控制,通常应用在刷写APP软件时,降低总线负载。这里首先要提醒的一点是,28服务几乎不需要手写代码,只有在客户需求要求前置条件不满足时报特定NRC时才需要填充代码。实际配置中主要涉及的模块有DCM,BSWM,ComM,RTE.2.BswM模块的配置。3.ComM模块的配置。1.DCM模块的配置。

Forever_Oct的博客 3096

POJ 2029 Get Many Persimmon Trees(水题)

题意:在w*h(最大100*100)的棋盘上,有的格子中放有一棵树,有的没有。问s*t的小矩形,最多能含有多少棵树。 解法:最直接的想法,设d[x1][y1][x2][y2]表示选择以(x1, y1)为左下角,以(x2, y2)为右上角的矩形含有多少棵树。然后就可以很容易地递推了。可是空间复杂度为O(10^8)不能被接受。    又发现d[x1][y1][x2][y2] = d[1][1][x...

weixin_33948416的博客 136

基于matlab的心电信号预处理

这是前段时间做的一个课程设计,做的比较简单,没有考虑到太细,只是初步地达到了想要的效果。这次设计主要是对心电信号进行预处理,将其信号中包含的一些干扰滤除或者抑制掉。 一、心电信号 (1)心电信号的特性   人体心电信号是非常微弱的生理低频电信号,通常最大的幅值不超过5mV,信号频率在0.05~100Hz之间。心电信号是通过安装在人体皮肤表面的电极来拾取的。由于电极和皮肤组织之间会发生极化现象

i_weimoli的博客 6万+

业务建模核心方法论与DDD实战指南

业务建模是系统设计的核心环节,通过抽象业务逻辑和流程关系构建数字化蓝图。其核心原理在于解构价值链、定义协作模型和封装业务规则,采用领域驱动设计(DDD)等方法建立业务与技术的统一语言。在电商、金融等高复杂度场景中,精准的业务建模可提升60%以上的流程效率,避免因早期建模缺陷导致的架构返工。典型技术实现涉及状态机模式、规则引擎等组件,其中Drools规则引擎能有效管理50+业务规则,而事件溯源模式则为金融等强审计需求场景提供解决方案。现代工程实践更结合数字孪生技术,实现业务系统的实时仿真与优化。

weixin_29443363的博客 198

poj 2029 Get Many Persimmon Treest

Get Many Persimmon Trees 题目链接:传送门 题目大意:在给定的w*h面积的土地上,随机种了一些树,给你s*t面积的矩形,让你圈儿出最多树。 类比一维的最长子串儿,这里也要初始化一个数组,记录从map[1][1]到map[x][y]之间的树的数量。 最后遍历每一个s*t大小的矩形。 代码如下: #include #inc

Singular__point的博客 533

告别玄学调参:手把手教你用LSTM-AutoEncoder为传感器数据做异常检测(实战篇)

本文详细介绍了LSTM-AutoEncoder在传感器数据异常检测中的工程化实践,包括数据预处理、模型架构设计和生产环境部署策略。通过结合LSTM的时间序列处理能力和AutoEncoder的特征提取优势,该方法能够有效识别温湿度、PM2.5等传感器数据的异常模式,适用于工业物联网和室内空气质量监测等场景。

weixin_29212429的博客 479

【poj 2029】Get Many Persimmon Trees 题意&题解

poj 暴力

曾经追梦的happy时光 613

【51单片机仿真】基于51单片机设计的多功能电子时钟日历(实时时钟闹钟秒表温度检测)系统__资料编号5

该项目是基于单片机的多功能电子时钟系统,集成了时间显示、闹钟设置、秒表功能以及温度显示等功能。主要硬件包括1602液晶显示屏、DS1302时钟芯片、DS18B20温度传感器和蜂鸣器。系统通过按键进行时间和闹钟的设置,并实时显示当前时间和温度。

嵌入式阿齐Archie 2万+

【第07例】IPD体系进阶: 6 个技术评审点(TR)

TR技术评审点

产品线负责人 4438

poj 2029 Get Many Persimmon Trees (DP)3Ways

//题意:在一个n*m的地图里有N棵树,问h*w面积内最多有多少棵树.\ dp[i][j]表示以(0,0)和(i,j)为对角点的面积中树的个数 #include using namespace std; int map[505][505],dp[505][505]; int main() { int N,H,W,h,w,i,j; while(cin>>N&&N) { memset(m

LH 515

微信小程序云开发 - 实现商家转账到零钱(微信企业付款到零钱) V3功能流程及完整实例代码,过微信云开发的云函数实现企业付款到零钱(提供详细示例源码纯云函数实现,证书、密钥、签名等各种常见问题解决方案

企业付款到零钱(微信小程序提现功能,提现到零钱)微信小程序-云函数实现微信企业付款到零钱功能,实现微信商户号中的企业付款到零钱的功能,微信小程序+云开发+商家转账至零钱+微信小程序用户提现,使用云开发环境的云函数实现微信小程序的支付功能,微信小程序实现微信企业付款到零钱功能的流程,V3 V2基于微信云开发的商家转账至零钱,小程序云函数企业付款到零钱功能实现,云开发实现微信商户支付企业付款到零钱功能,不用服务器纯云函数实现,详细示例代码demo教程,API证书错误,转账不到账怎么办,密钥生成有误,转账失败,有

🏆 前端领域优质创作者 1万+

POJ 2029 Get Many Persimmon Trees [dp]

题意: 给一个矩阵,里面分布着n个星号。 给定一个小矩阵,问最大可以圈进多少个星号。 思路: dp方程: dp1[i][j]=dp1[i-1][j]+dp1[i][j-1]-dp1[i-1][j-1]+a[i][j];//代表从(1,1)到(j,i)圈进的星数。 dp2[i][j]=dp1[i][j]-dp1[i-ty][j]-dp1[i][j-tx]+dp1[i-ty][j-tx];

Aszxqw 729

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

poj- 2029 -Get Many Persimmon Trees (DP)

http://poj.org/problem?id=2029 Description Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him f

Vision 411

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

poj 2029 Get Many Persimmon Trees(dp)

这道题由于数据量较小,全然能够暴力,用dp做先处理所有前缀,这样的复杂度是n*m,比暴力的复杂度低,暴力的复杂度是n*m*s*t //#include #include #include #include #include using namespace std; int map1[105][105],dp[105][105]; int main() { int n; while(~s

但求心安的博客 299

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

POJ2029:Get Many Persimmon Trees(DP)

Get Many Persimmon Trees Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 2821   Accepted: 1836 Description Seiji Hayashi had been a professor of the Nisshinkan

飘羽逸狂 328

POJ 2029--Get Many Persimmon Trees +DP

题意: 在一个w*h宽的矩形中有些位置有树有些位置没有,然后我们需要从中选一个s*t的矩形,使得里面含有的树最多. 思路: 我们将有树位置的值看成1,其它为0,然后成了选一个区域值最大.然后考虑这个问题的一维形式,在一维的情况下,我们很容易得到一个方案:先处理前缀和,然后就可以枚举区间端点的起点,O(1)时间计算区间和,然后取其中的最大值为答案. 这道题我们可以按同样的思路来做,先求出(1,1)

荒野孤鹰 811

poj2029--Get Many Persimmon Trees(dp)

Get Many Persimmon Trees Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3708   Accepted: 2410 Description Seiji Hayashi had been a professor of the Nisshinkan

随风的专栏 1535

poj 2029 Get Many Persimmon Trees (dp)

题目链接 又是一道完全自己想出来的dp题。 题意:一个w*h的图中,有n个点,给一个s*t的圈,求这个圈能 圈的最多的点 分析:d[i][j]代表i行j列 到第一行第一列的这个方框内有多少个点, 然后枚举圈的右下角的点, 计算在圈的范围的点的方法为 d[i][j]-d[i][j-s]-d[i-t][j]+d[i-t][j-s]。 1 #include <iostream&...

weixin_30237281的博客 90

POJ 2029 Get Many Persimmon Trees(DP)

题目链接 和求最大子矩阵和,神似。。。宝哥用树状数组做的,数据量挺小的,我直接暴力O(n^2)水过了。。 1 #include <stdio.h> 2 #include <string.h> 3 int p[101][101],o[101][101],map[101][101],key[101][101]; 4 int main() 5 { 6...

weixin_30689307的博客 84

poj 2029 Get Many Persimmon Trees (水题 dp)

http://poj.org/problem?id=2029 题意: 一个 矩形内有 许多树,给你 一个 长和寬一定的 小矩形,问最多 能 用小矩形 盖住多少棵树 枚举求和: 1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #includ...

weixin_30527143的博客 71

POJ 2029 Get Many Persimmon Trees DP/二维树状数组/线段树

题意:给定一个由坐标系构成的柿子树林,有的坐标点上存在柿子树,有的不存在。现在准备送给你一块土地,土地的长和宽已经确定,怎么选才能使给你的土地上的柿子树最多。 题解:这道题和 2482 Stars in Your Window 颇为相似。下面给出了三种解法。 方法一:DP #include using namespace std; #define N 103 int

738
上一篇: 【POJ 1925】 Spiderman(dp)
下一篇: 【POJ 3071】 Football(DP)
枕星zxLumen
博客等级 码龄12年 178粉丝 367原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值