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 ...
随机推荐
- 使用libuv实现生产者和消费者模式
生产者和消费者模式(Consumer + Producer model) 用于把耗时操作(生产线程),分配给一个或者多个额外线程执行(消费线程),从而提高生产线程的响应速度(并发能力) 定义 type ...
- Windows Phone 8.1 与 Windows Phone 8.1 Silverlight区别
以下讨论基于当前的WP8 APP, 一.Windows Phone 8 app:旧的WP8程序:不需要迁移: 二.Windows Phone 8.1 app新的使用Windows Runtime 的程 ...
- HTTP 错误 403.14 - Forbidden
在打开一个网站时,显示HTTP 错误 403.14 - Forbidden 是一件很不幸的事情.我这几天打开某网站就出现了这个问题.Web 服务器被配置为不列出此目录的内容,错误代码0x0000000 ...
- C语言关键字register、extern、static
C语言中: 一.register变量 关键字regiter请求编译器尽可能的将变量存在CPU的寄存器中.有以下几点注意的地方. register变量必须是能被CPU寄存器所接受的类型,这通常意味着re ...
- HDU4276 The Ghost Blows Light SPFA&&树dp
题目的介绍以及思路完全参考了下面的博客:http://blog.csdn.net/acm_cxlove/article/details/7964739 做这道题主要是为了加强自己对SPFA的代码的训练 ...
- POJ2104 k-th number 划分树
又是不带修改的区间第k大,这次用的是一个不同的方法,划分树,划分树感觉上是模拟了快速排序的过程,依照pivot不断地往下划分,然后每一层多存一个toleft[i]数组,就可以知道在这一层里从0到i里有 ...
- **【ci框架】PHP的CI框架集成Smarty的最佳方式
因为CI自带的模板功能不是很方便,所以大家普遍采用集成Smarty的方式来弥补CI这方面的不足. 本人在网上看了不少CI集成Smarty的教程,包括咱们CI论坛里面的一个精华帖子 http://cod ...
- hdu 4412 Sky Soldiers DP
动态规划,主要是用单调性求区间的最小期望. 代码如下: #include<iostream> #include<stdio.h> #include<algorithm&g ...
- Happy Number
https://leetcode.com/problems/happy-number/ Write an algorithm to determine if a number is "hap ...
- javascript 在一个函数参数中包含另一个函数的引用
javascript函数的参数包含另一个函数的情形: <script> //b函数的参数func为另一个函数 function b(a, func) { alert(a); //调用参数 ...