题意:在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][x2][y2] - d[1][1][x1-1][y2] - d[1][1][x2][y1-1] + d[1][1][x1-1][y1-1],所以只需要预处理出所有的d[1][1][i][j]即可,然后每次求出一个d[x1][y1][x2][y2]就与ans比较,不用存下来。

tag:DP

 /*
* Author: Plumrain
* Created Time: 2013-11-18 01:05
* File Name: DP-POJ-2029.cpp
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; #define CLR(x) memset(x, 0, sizeof(x)) int n, w, h, s, t;
bool has[][];
int d[][][][]; void init()
{
scanf ("%d%d", &w, &h);
int t1, t2;
CLR (has);
for (int i = ; i < n; ++ i){
scanf ("%d%d", &t1, &t2);
has[t1][t2] = ;
}
scanf ("%d%d", &s, &t);
} int DP()
{
int ret = ;
CLR (d);
ret = d[][][][] = has[][];
for (int i = ; i <= w; ++ i)
d[][][i][] = d[][][i-][] + has[i][];
for (int i = ; i <= h; ++ i)
d[][][][i] = d[][][][i-] + has[][i]; for (int i = ; i <= w; ++ i)
for (int j = ; j <= h; ++ j)
d[][][i][j] = has[i][j] + d[][][i-][j] + d[][][i][j-] - d[][][i-][j-]; for (int x1 = ; x1 <= w; ++ x1)
for (int y1 = ; y1 <= h; ++ y1)
for (int x2 = x1; x2 <= min(x1+s-, w); ++ x2)
for (int y2 = y1; y2 <= min(y1+t-, h); ++ y2)
ret = max(ret, d[][][x2][y2] - d[][][x1-][y2] - d[][][x2][y1-] + d[][][x1-][y1-]);
return ret;
} int main()
{
while (scanf ("%d", &n) != EOF && n){
init();
printf ("%d\n", DP());
}
return ;
}

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 (模板题)【二维树状数组】

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

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

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

  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(DP||二维树状数组)

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

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

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

  9. [POJ 1000] A+B Problem 经典水题 C++解题报告 JAVA解题报告

        A+B Problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 311263   Accepted: 1713 ...

随机推荐

  1. java I/O的基本使用

    1.什么是I/O a.I/O也称为:输入输出,可以理解为In,Out b.I/O流:读取键盘键入的字符,硬盘上的文件 c.处理数据的类型分类:字节流.字符流 字节流:以Stream结尾的,可以处理图片 ...

  2. oracle decode函数使用方法

    1.decode(V1,1,A,2,B,C) 如果V1=1 那么显示A =2显示B 其他显示C ........ 2. 含义解释:  decode(条件,值1,返回值1,值2,返回值2,...值n,返 ...

  3. tableView嵌套collectionView

    首先是自定义collectionView填充的tableViewCell import UIKit // 定义一个collectionView,重写初始化大小和布局方法 class TrendsDet ...

  4. Core Animation之CAKeyframeAnimation

    在上一篇专题文章中我们学习了iOS核心动画CoreAnimation中CABasicAnimation动画的使用方法.CABasicAnimation已经可以应付一些比较简单的应用场景了,比如view ...

  5. Linux命令:scp命令(文件上传和下载)

    #本地下载远端文件 并且重命名(从本地机器下载远端) scp webmaster@10.10.65.103:/ROOT/logs/tomcate.log /home/dajie/mywork/newn ...

  6. servlet的提交

    servlet的提交和动态改变有点依赖xml 我们点击控件的时候改变了里面的变量,改变了xml,servlet发现变量变了,就会刷新页面 如果xml文档没有更新,浏览器采用缓存而不则行 <for ...

  7. 【HOJ2430】【贪心+树状数组】 Counting the algorithms

    As most of the ACMers, wy's next target is algorithms, too. wy is clever, so he can learn most of th ...

  8. TaskbarCreated 消息

    托盘中的图片就通过注册这个消息来实现,系统和进程通过进程间通信发送这个消息,进程接收他

  9. .getBoundingClientRect()

    .getBoundingClientRect() 该方法获得页面中某个元素的左,上,右和下分别相对浏览器视窗的位置,他返回的是一个对象,即Object,该对象有4个属性:top,left,right, ...

  10. PHP面向对象(OOP):.static和const关键字的使用(self::)

    static关键字是在类中描述成员属性和成员方法是静态的:静态的成员好 处在哪里呢?前面我们声明了“Person”的人类,在“Person”这个类里如果我们加上一个“人所属国家”的属性,这样用“Per ...