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 ...
随机推荐
- Switch Case语句中多个值匹配同一个代码块的写法
switch ($p) { case 'home': case '': $current_home = 'current'; break; case 'users.online': case 'use ...
- Spring通过SchedulerFactoryBean实现调度任务的配置
http://blog.csdn.net/hu_shengyang/article/details/19815201(里面是配置) 介绍SchedulerFactoryBean http://blog ...
- Cookie技术详解
1. Cookie的特性 属性: 1> name: Cookie的名字 2> value: Cookie的值 3> path: 可选,Cookie的存储路径,默认情况下的存储路径时访 ...
- JavaScript学习笔记--ES6学习(五) 数值的扩展
ES6 对于数值类型 (Number) 进行了一下扩展: 1.对于二进制和八进制提供了新的写法 ES6对于二进制和八进制的数值提供了新的写法,分别用0b (或者0B) 和0o (或者0o) 表示.例如 ...
- LA 6856 Circle of digits 解题报告
题目链接 先用后缀数组给串排好序.dc3 O(n) 二分答案+贪心check 答案的长度len=(n+k-1)/k 如果起点为i长为len串大于当前枚举的答案,i的长度取len-1 从起点判断k个串的 ...
- java.lang.String类compareTo()返回值解析
一.compareTo()的返回值是int,它是先比较对应字符的大小(ASCII码顺序)1.如果字符串相等返回值02.如果第一个字符和参数的第一个字符不等,结束比较,返回他们之间的差值(ascii码值 ...
- phpcms V9利用num++实现多样形式列表标签调用
在首页或者频道页调用文章列表的时候,经常会使用到左右对称或者每五行出现一条横线的调用形式. 其实代码很简单,利用num++的循环方式,以及{if}{/if}进行样式判断即可.代码如下: {pc:con ...
- sql查询一个班级中总共有多少人以及男女分别多少人
--创建视图 create view StuClassView as SELECT s.ID ,s.StuName ,s.StuAge ,s.StuAddress ,s.StuTel ,s.Class ...
- 通过命令修改wampserver的mysql密码
WAMP安装好后,mysql教程密码是为空的,那么要如何修改呢?其实很简单,通过几条指令就行了,下面我就一步步来操作. 首先,通过WAMP打开mysql控制台. 提示输入密码,因为现在是空,所以直接按 ...
- TatukGIS - GisDefs - CheckFileWriteAccess 函数
函数名称 CheckFileWriteAccess 所在单元 GisDefs 函数原型 1 function CheckFileWriteAccess(const _file ...