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][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(水题)的更多相关文章
- (简单) POJ 2029 Get Many Persimmon Trees,暴力。
Description Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aiz ...
- POJ 2029 Get Many Persimmon Trees (二维树状数组)
Get Many Persimmon Trees Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I ...
- POJ 2029 Get Many Persimmon Trees
Get Many Persimmon Trees Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 3243 Accepted: 2 ...
- POJ 2029 Get Many Persimmon Trees (模板题)【二维树状数组】
<题目链接> 题目大意: 给你一个H*W的矩阵,再告诉你有n个坐标有点,问你一个w*h的小矩阵最多能够包括多少个点. 解题分析:二维树状数组模板题. #include <cstdio ...
- poj 2029 Get Many Persimmon Trees 各种解法都有,其实就是瞎搞不算吧是dp
连接:http://poj.org/problem?id=2029 题意:给你一个map,然后在上面种树,问你h*w的矩形上最多有几棵树~这题直接搜就可以.不能算是DP 用树状数组也可作. #incl ...
- poj 2029 Get Many Persimmon Trees (dp)
题目链接 又是一道完全自己想出来的dp题. 题意:一个w*h的图中,有n个点,给一个s*t的圈,求这个圈能 圈的最多的点 分析:d[i][j]代表i行j列 到第一行第一列的这个方框内有多少个点, 然后 ...
- POJ 2029 Get Many Persimmon Trees(DP||二维树状数组)
题目链接 题意 : 给你每个柿子树的位置,给你已知长宽的矩形,让这个矩形包含最多的柿子树.输出数目 思路 :数据不是很大,暴力一下就行,也可以用二维树状数组来做. #include <stdio ...
- POJ 2029 Get Many Persimmon Trees 【 二维树状数组 】
题意:给出一个h*w的矩形,再给出n个坐标,在这n个坐标种树,再给出一个s*t大小的矩形,问在这个s*t的矩形里面最多能够得到多少棵树 二维的树状数组,求最多能够得到的树的时候,因为h,w都不超过50 ...
- [POJ 1000] A+B Problem 经典水题 C++解题报告 JAVA解题报告
A+B Problem Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 311263 Accepted: 1713 ...
随机推荐
- windows Server 2008 -必须使用“角色管理工具”安装或配置Microsoft .Net Framework 3.5
在windows Server 2008上安装 .Net Framework 3.5的时候,报错:必须使用“角色管理工具”安装或配置Microsoft .Net Framework 3.5. Solu ...
- bootstrap 下的 validation插件
http://reactiveraven.github.io/jqBootstrapValidation/
- CentOS 7重装mysql编译过程报错解决方法
错误记录: [ 82%] Building C object libmysql/CMakeFiles/clientlib.dir/__/sql-common/client.c.o/usr/local/ ...
- 用Ueditor存入数据库带HTML标签的文本,从数据库取出来后,anjular用ng-bind-html处理带HTML标签的文本
ng.module('index-filters', []) .filter('trustHtml', function ($sce) { return function (input) { retu ...
- C#堆栈原理(我有两个例子测试你到底会不会)
背景 上次写了一篇文章关于try finnally的一些疑问(被我用windows live覆盖了,草),后来经过大神们解释,我明白了在我理解了try.finnally运行原理后,还欠缺的就是关于值类 ...
- Html5实现头像上传和编辑,保存为Base64的图片过程
一.Html5实现头像上传和编辑 插件地址: html5手机端裁剪图片上传头像代码 本地项目引入注意事项: 1.将html的js搬到外面的js文件中,便于管理 2.图片样式在html都是在页面写死,需 ...
- java dos下中文乱码
代码如下: public class PrintString{ public static void main(String args[]){ System.out.println("\\* ...
- IOS下双击背景, touchmove, 阻止页面背景scroll.
ios prevent dblclick(tap) page scrollhtml add:("minimal-ui" is very important) <meta na ...
- NodeJs开发学习目录
1.Nodejs基本概念及Nodejs.npm安装测试[2014-06-06] 2.开发工具简介(主要介绍Sublime Text使用) [2014-06-06] 3.Sublime text插件安装 ...
- c#xml序列化对象,xml标记都缩写了
最近最后一个接口,他们的格式很严格必须是如下格式 <message> <age>20</age> <name>张三</name> </ ...