题意:在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. jquery ui 插件------------------------->sortable

    <!doctype html><html lang="en"><head>  <meta charset="utf-8" ...

  2. IIS 64位上發佈32位asp.net設置

    錯誤:無法載入檔案或組件 'Maticsoft.Web' 或其相依性的其中之一. 試圖載入格式錯誤的程式. 解決:新增應用程序池——高級設置——啟用32位應用程式——True

  3. tomcat发布项目时,空文件夹未发布成功

    问题背景: 项目发布到服务器时,缺少文件夹,到时向此文件夹写数据时发生错误. 后来经查,缺少这个文件夹,项目部署发布时,并不会把空文件夹发布上去 解决: 1.在空文件中加入,一个文件.就可以发布成功 ...

  4. webpack学习笔记一(入门)

    webpack集成了模块加载和打包等功能 ,这两年在前端领域越来越受欢迎.平时一般是用requirejs.seajs作为模块加载用,用grunt/gulp作为前端构建.webpack作为模块化加载兼容 ...

  5. css media

    /* media */ /* 横屏 */ @media screen and (orientation:landscape){ } /* 竖屏 */ @media screen and (orient ...

  6. 【BZOJ2653】【主席树+二分】middle

    Description 一个长度为n的序列a,设其排过序之后为b,其中位数定义为b[n/2],其中a,b从0开始标号,除法取下整. 给你一个长度为n的序列s. 回答Q个这样的询问:s的左端点在[a,b ...

  7. js转换/Date(........)/

    eval('new ' + (datetime.replace(/\//g, ''))); 好记性不如烂笔头,记下以备后用.

  8. MySQL5.7.9免安装版配置方法

    1. 解压MySQL压缩包    将下载的MySQL压缩包解压到自定义目录下,我的解压目录是:    "D:\Program Files\mysql-5.7.9-win32"    ...

  9. TCP协议握手与分手

    TCP(Transmission Control Protocol) 传输控制协议 TCP的7次握手可以理解为3次握手和4次分手. TCP状态转换图,如下: 这个图N多人都知道,它对排除和定位网络或系 ...

  10. C# Hashtable中存入数组、List

    哈希表中存入数组示例代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; ...