poj 2029 Get Many Persimmon Trees (dp)
又是一道完全自己想出来的dp题。
题意:一个w*h的图中,有n个点,给一个s*t的圈,求这个圈能 圈的最多的点
分析:d[i][j]代表i行j列 到第一行第一列的这个方框内有多少个点, 然后枚举圈的右下角的点,
计算在圈的范围的点的方法为
d[i][j]-d[i][j-s]-d[i-t][j]+d[i-t][j-s]。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define LL long long
using namespace std;
const int maxn = + ;
int d[][], G[][];
int n, w, h, s, t; int main()
{
int i, j, x, y, sum, ans;
while(~scanf("%d", &n) && n)
{
ans = ;
memset(d, , sizeof(d));
memset(G, , sizeof(G));
scanf("%d%d", &w, &h);
for(i = ; i <= n; i++)
{
scanf("%d%d", &x, &y);
G[y][x] = ;
}
scanf("%d%d", &s, &t);
for(i = ; i <= h; i++)
{
sum = ;
for(j = ; j <= w; j++)
{
if(G[i][j] == )
sum++;
d[i][j] = d[i-][j] + sum;
}
}
for(i = t; i <= h; i++)
for(j = s; j <= w; j++)
{
ans = max(ans, d[i][j]-d[i][j-s]-d[i-t][j]+d[i-t][j-s]);
}
printf("%d\n", ans);
}
return ;
}
poj 2029 Get Many Persimmon Trees (dp)的更多相关文章
- (简单) 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 各种解法都有,其实就是瞎搞不算吧是dp
连接:http://poj.org/problem?id=2029 题意:给你一个map,然后在上面种树,问你h*w的矩形上最多有几棵树~这题直接搜就可以.不能算是DP 用树状数组也可作. #incl ...
- POJ 2029 Get Many Persimmon Trees(DP||二维树状数组)
题目链接 题意 : 给你每个柿子树的位置,给你已知长宽的矩形,让这个矩形包含最多的柿子树.输出数目 思路 :数据不是很大,暴力一下就行,也可以用二维树状数组来做. #include <stdio ...
- POJ 2029 Get Many Persimmon Trees(水题)
题意:在w*h(最大100*100)的棋盘上,有的格子中放有一棵树,有的没有.问s*t的小矩形,最多能含有多少棵树. 解法:最直接的想法,设d[x1][y1][x2][y2]表示选择以(x1, y1) ...
- POJ 2029 Get Many Persimmon Trees (模板题)【二维树状数组】
<题目链接> 题目大意: 给你一个H*W的矩阵,再告诉你有n个坐标有点,问你一个w*h的小矩阵最多能够包括多少个点. 解题分析:二维树状数组模板题. #include <cstdio ...
- POJ 2029 Get Many Persimmon Trees 【 二维树状数组 】
题意:给出一个h*w的矩形,再给出n个坐标,在这n个坐标种树,再给出一个s*t大小的矩形,问在这个s*t的矩形里面最多能够得到多少棵树 二维的树状数组,求最多能够得到的树的时候,因为h,w都不超过50 ...
- poj2029 Get Many Persimmon Trees
http://poj.org/problem?id=2029 单点修改 矩阵查询 二维线段树 #include<cstdio> #include<cstring> #inclu ...
随机推荐
- 【BZOJ 1068】[SCOI2007]压缩
Description 给 一个由小写字母组成的字符串,我们可以用一种简单的方法来压缩其中的重复信息.压缩后的字符串除了小写字母外还可以(但不必)包含大写字母R与M,其中M 标记重复串的开始,R重复从 ...
- PHP之SQL防注入代码集合(建站常用)
SQL防注入代码一 <?php if (!function_exists (quote)) { function quote($var) { if (strlen($var)) { $var=! ...
- 用Ant实现Java项目的自动构建和部署(转)
Ant是一个Apache基金会下的跨平台的构件工具,它可以实现项目的自动构建和部署等功能.在本文中,主要让读者熟悉怎样将Ant应用到Java项目中,让它简化构建和部署操作. 一. ...
- uva 757
贪心 优先队列 #include <cstdio> #include <cstdlib> #include <cmath> #include <map> ...
- javascript加速运动
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- linux入门教程(八) Linux磁盘管理
[查看磁盘或者目录的容量 df 和 du] df 查看已挂载磁盘的总容量.使用容量.剩余容量等,可以不加任何参数,默认是按k为单位显示的 df常用参数有 –i -h -k –m等 -i 使用inode ...
- hdu1017
http://acm.hdu.edu.cn/showproblem.php?pid=1017 #include<iostream> #include<stdio.h> #inc ...
- 小米2S 连接Ubuntu Android Studio
1. 首先打开手机上的开发者选项,USB调试.拨号:*#*#717717#*#* ,手机会以Toast形式出现“……enable”字样.再次拨号可disable. 2. Ubuntu安装mtpfs: ...
- 最长不下降子序列//序列dp
最长不下降子序列 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 求最长不下降子序列的长度 输入格式 第一行为n,表示n个数第二行n个数 输出格式 最长不下降 ...
- JAVA:23种设计模式详解(转)
设计模式(Design Patterns) ——可复用面向对象软件的基础 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了 ...