USACO Section 5.3 Big Barn(dp)

USACO前面好像有类似的题目..dp(i,j)=min(dp(i+1,j),dp(i+1,j+1),dp(i,j+1))+1 (坐标(i,j)处无tree;有tree自然dp(i,j)=0) 。dp(i,j)表示以坐标(i,j)为左上角的barn边长最大值,dp(i+1,j),dp(i,j+1)分别表示向右和向下能扩展的最大边长,但是以此为正方形时,右下方的一个格子没有考虑到,所以就+个dp(i+1,j+1)。边界为:dp(i,j)=1(i==n-1或j==n-1)。
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Big Barn
A Special Treat
Farmer John wants to place a big square barn on his square farm. He hates to cut down trees on his farm and wants to find a location for his barn that enables him to build it only on land that is already clear of trees. For our purposes, his land is divided into N x N parcels. The input contains a list of parcels that contain trees. Your job is to determine and report the largest possible square barn that can be placed on his land without having to clear away trees. The barn sides must be parallel to the horizontal or vertical axis.
EXAMPLE
Consider the following grid of Farmer John's land where `.' represents a parcel with no trees and `#' represents a parcel with trees:
1 2 3 4 5 6 7 8 1 . . . . . . . . 2 . # . . . # . . 3 . . . . . . . . 4 . . . . . . . . 5 . . . . . . . . 6 . . # . . . . . 7 . . . . . . . . 8 . . . . . . . .
The largest barn is 5 x 5 and can be placed in either of two locations in the lower right part of the grid.
PROGRAM NAME: bigbrn
INPUT FORMAT
| Line 1: | Two integers: N (1 <= N <= 1000), the number of parcels on a side, and T (1 <= T <= 10,000) the number of parcels with trees |
| Lines 2..T+1: | Two integers (1 <= each integer <= N), the row and column of a tree parcel |
SAMPLE INPUT (file bigbrn.in)
8 3 2 2 2 6 6 3
OUTPUT FORMAT
The output file should consist of exactly one line, the maximum side length of John's barn.
SAMPLE OUTPUT (file bigbrn.out)
5
USACO Section 5.3 Big Barn(dp)的更多相关文章
- USACO Section 5.3 Milk Measuring (IDDFS+dp)
迭代加深搜索,从小到大枚举桶数的上限maxd:对每个maxd,枚举每个组合,判断是否能够倒出q:直到得到answer.判断的部分就用dp(完全背包). ------------------------ ...
- USACO Section 1.3 Barn Repair 解题报告
题目 题目描述 某农夫有一个养牛场,所有的牛圈都相邻的排成一排(共有S个牛圈),每个牛圈里面最多只圈养一头牛.有一天狂风卷积着乌云,电闪雷鸣,把牛圈的门给刮走了.幸运的是,有些牛因为放假,所以没在自己 ...
- [USACO Section 5.3]量取牛奶 Milk Measuring (动态规划,背包$dp$)
题目链接 Solution 完全背包 \(dp\) , 同时再加一个数组 \(v[i][j]\) 记录当总和为\(j\) 时第 \(i\) 种物品是否被选. 为保证从小到大和字典序,先将瓶子按大小排序 ...
- USACO Section 1.3 题解 (洛谷OJ P1209 P1444 P3650 P2693)
usaco ch1.4 sort(d , d + c, [](int a, int b) -> bool { return a > b; }); 生成与过滤 generator&& ...
- USACO 6.1 A Rectangular Barn
A Rectangular Barn Mircea Pasoi -- 2003 Ever the capitalist, Farmer John wants to extend his milking ...
- 【USACO 2.2】Subset Sums (DP)
N (1 <= N <= 39),问有多少种把1到N划分为两个集合的方法使得两个集合的和相等. 如果总和为奇数,那么就是0种划分方案.否则用dp做. dp[i][j]表示前 i 个数划分到 ...
- 【USACO 3.2】Stringsobits (dp)
题意:求第k大的最多有l个1的n位二进制. 题解:dp[i][j]表示长度为i最多有j个1的二进制有多少种,则有: 状态转移:dp[i][j]=dp[i-1][j]+dp[i-1][j-1],即第i位 ...
- USACO Section 3.3 商店购物 Shopping Offers
题目背景 在商店中,每一种商品都有一个价格(用整数表示).例如,一朵花的价格是 2 zorkmids (z),而一个花瓶的价格是 5z .为了吸引更多的顾客,商店举行了促销活动. 题目描述 促销活动把 ...
- USACO Section 3.2 01串 Stringsobits
题目背景 考虑排好序的N(N<=31)位二进制数. 题目描述 他们是排列好的,而且包含所有长度为N且这个二进制数中1的位数的个数小于等于L(L<=N)的数. 你的任务是输出第i(1< ...
随机推荐
- dg error
startup force;ORACLE instance started. Total System Global Area 1068937216 bytesFixed Size ...
- 数学题(找规律)-hdu-4371-Minimum palindrome
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4731 题目大意: 给一个n表示有n种字母(全部小写),给一个m,求一个由不超过n种字母组成的m个小写 ...
- grivid中切换按钮,两个按钮交替
给grivdView不要设值 button的url和 commandName 在rowDatabound中操作变换 protected void GVData_RowDataBound(object ...
- image元素的src属性值与getAttribute('src')值
采集的时候,当采集到一些不可用的照片就将其剔除掉 我的解决思路是new一个img对象, 然后将采集过来的图片赋值给这个img, 然后分别处理img的onerror和 onload, 当在onerror ...
- CentOS6.3下安装配置SVN(Subversion)
#检查是否安装了低版本的SVN [root@localhost ~]# rpm -qa subversion subversion--.el6.x86_64 #卸载旧版本SVN [root@local ...
- VC++ SetLayeredWindowAttributes 部分窗口透明鼠标穿透
在初始化中使用下面两行代码 ModifyStyleEx(0, WS_EX_LAYERED); ::SetLayeredWindowAttributes(m_hWnd, RGB(1, 255, 0), ...
- Centos 7 安装Mono和Jexus 默认目录安装 (一)
一.准备环境 yum -y install gcc gcc-c++ bison pkgconfig glib2-devel gettext make libpng-devel libjpeg-deve ...
- Django Web开发【6】使用Ajax增强用户体验
Ajax及其优点 Ajax实际上就是指异步Javascript与XML,它包含以下技术: HTML与CSS Javascript XMLHttpRequest XML Ajax技术让客户端与服务器实现 ...
- 公选网站作业4_2.php
序: 此实验的功能是只有已经登陆或者已经注册的用户才有发表留言的资格,否则只能够浏览留言. 1. 主要文件: 4_2login.html// 登陆的主页面 4_2login.php //处理登 ...
- hdu 4735Little Wish~ lyrical step~ 重复覆盖
题目链接 给出一棵树, 树上点的值为0或1, 可以交换树上两个点的权值, 给出一个距离m, 所有的0距离最近的1的距离不能超过m, 求最少的交换次数. 首先对于每一个点u,所有离u的距离不超过m的点v ...