Get Many Persimmon Trees

Time Limit: 1000MS Memory Limit: 30000K

Total Submissions: 3987 Accepted: 2599

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

可以将二维转换成一维,然后在dp求解

#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdlib.h> using namespace std;
int dp[105];
int d[105];
int c[105][105];
int n;
int x,y;
int a,b;
int w,h;
int main()
{
int ans;
int sum;
while(scanf("%d",&n)!=EOF)
{
if(n==0)
break;
ans=0;
scanf("%d%d",&a,&b);
memset(c,0,sizeof(c));
for(int i=1;i<=n;i++)
{
scanf("%d%d",&x,&y);
c[y][x]=1;
}
scanf("%d%d",&w,&h);
for(int i=1;i<=b-h+1;i++)
{
memset(d,0,sizeof(d));
memset(dp,0,sizeof(dp));
for(int p=0;p<h;p++)
for(int j=1;j<=a;j++)
d[j]+=c[i+p][j];
for(int k=1;k<=w;k++)
dp[w]+=d[k];
for(int j=w+1;j<=a;j++)
{
sum=0;
for(int k=j;k>=j-w+1;k--)
sum+=d[k];
dp[j]=max(dp[j-1],sum); } if(ans<dp[a])
ans=dp[a];
}
printf("%d\n",ans);
}
}

POJ-2029 Get Many Persimmon Trees(动态规划)的更多相关文章

  1. (简单) POJ 2029 Get Many Persimmon Trees,暴力。

    Description Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aiz ...

  2. POJ 2029 Get Many Persimmon Trees (二维树状数组)

    Get Many Persimmon Trees Time Limit:1000MS    Memory Limit:30000KB    64bit IO Format:%I64d & %I ...

  3. POJ 2029 Get Many Persimmon Trees

    Get Many Persimmon Trees Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3243 Accepted: 2 ...

  4. poj 2029 Get Many Persimmon Trees 各种解法都有,其实就是瞎搞不算吧是dp

    连接:http://poj.org/problem?id=2029 题意:给你一个map,然后在上面种树,问你h*w的矩形上最多有几棵树~这题直接搜就可以.不能算是DP 用树状数组也可作. #incl ...

  5. POJ 2029 Get Many Persimmon Trees(DP||二维树状数组)

    题目链接 题意 : 给你每个柿子树的位置,给你已知长宽的矩形,让这个矩形包含最多的柿子树.输出数目 思路 :数据不是很大,暴力一下就行,也可以用二维树状数组来做. #include <stdio ...

  6. poj 2029 Get Many Persimmon Trees (dp)

    题目链接 又是一道完全自己想出来的dp题. 题意:一个w*h的图中,有n个点,给一个s*t的圈,求这个圈能 圈的最多的点 分析:d[i][j]代表i行j列 到第一行第一列的这个方框内有多少个点, 然后 ...

  7. POJ 2029 Get Many Persimmon Trees(水题)

    题意:在w*h(最大100*100)的棋盘上,有的格子中放有一棵树,有的没有.问s*t的小矩形,最多能含有多少棵树. 解法:最直接的想法,设d[x1][y1][x2][y2]表示选择以(x1, y1) ...

  8. POJ 2029 Get Many Persimmon Trees (模板题)【二维树状数组】

    <题目链接> 题目大意: 给你一个H*W的矩阵,再告诉你有n个坐标有点,问你一个w*h的小矩阵最多能够包括多少个点. 解题分析:二维树状数组模板题. #include <cstdio ...

  9. POJ 2029 Get Many Persimmon Trees 【 二维树状数组 】

    题意:给出一个h*w的矩形,再给出n个坐标,在这n个坐标种树,再给出一个s*t大小的矩形,问在这个s*t的矩形里面最多能够得到多少棵树 二维的树状数组,求最多能够得到的树的时候,因为h,w都不超过50 ...

随机推荐

  1. Java动态代理和静态代理区别

    静态代理 package staticproxy; /** * 接口 * @author newtouch * */ public interface IHello { public void say ...

  2. python tornado异步性能测试

    测试两个接口 # -*- coding:utf-8 -*- import time import tornado.web import tornado.gen import tornado.ioloo ...

  3. Git中的文件状态和使用问题解决

    (暂存区 即Index In Git) commit 到 local respository的内容,不想push,则使用git reset 将文件状态回转到staged|modified|unstag ...

  4. HTML 引用

    关于 HTML 引用: (1) <q> 和 <blockquote> 用于实现长短不一的引用语(2) <q> 用于短的引用,<blockquote> 用 ...

  5. setcursor 与 showcursor

    Windows为鼠标光标保存了一个「显示计数」.如果安装了鼠标,显示计数会被初始化为0:否则,显示计数会被初始化为-1. 只有在显示计数非负时才显示鼠标光标.要增加显示计数,呼叫:ShowCursor ...

  6. Apache HTTP Server 与 Tomcat 的三种连接方式介绍

    本文转载自IBM developer 首先我们先介绍一下为什么要让 Apache 与 Tomcat 之间进行连接.事实上 Tomcat 本身已经提供了 HTTP 服务,该服务默认的端口是 8080,装 ...

  7. Twitter的SnowFlake分布式id生成算法

    二进制相关知识回顾 1.所有的数据都是以二进制的形式存储在硬盘上.对于一个字节的8位到底是什么类型 计算机是如何分辨的呢? 其实计算机并不负责判断数据类型,数据类型是程序告诉计算机该如何解释内存块. ...

  8. UINavigationItem 设置UIBarButtonItem

    转:http://hi.baidu.com/ivan_xu/item/237bb1ad77eff9b028ce9d7c 有A.B两个ViewController,假如A push B: UINavig ...

  9. linux下压缩和解压

    .tar 解包:tar xvf FileName.tar打包:tar cvf FileName.tar DirName(注:tar是打包,不是压缩!)———————————————.gz解压1:gun ...

  10. 【黑金原创教程】【FPGA那些事儿-驱动篇I 】实验十四:储存模块

    实验十四比起动手笔者更加注重原理,因为实验十四要讨论的东西,不是其它而是低级建模II之一的模块类,即储存模块.接触顺序语言之际,“储存”不禁让人联想到变量或者数组,结果它们好比数据的暂存空间. . i ...