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< ...
随机推荐
- 有哪些适合学生参与的 C++,网络编程方面的开源项目?
有哪些适合学生参与的 C++,网络编程方面的开源项目? Tinyhttpd是一个超轻量型Http Server,使用C语言开发,全部代码只有502行(包括注释),附带一个简单的Client,可以通 ...
- Sublime text3使用积累
1.colorpicker选择颜色的. 快捷键ctrl+shift+C 2.jsFormat格式化js 快捷键ctrl+alt+f [ { "keys": ["ctrl+ ...
- 清风注解-Swift程序设计语言
前言 Apple 发布了全新的 Swift 程序设计语言,用来开发 iOS 和 OS X 平台的应用程序.其目的不言而喻:就是为了给老迈的 Objective-C 一个合适接班人!因此,不难预见,未来 ...
- 枚举与剪枝_观察算式(比标准答案还要牛B)
观察算式 观察以下的算式: △△△ * △△ = △△△△ 某3位数乘以2位数,结果为4位数 要求:在9个△所代表的数字中.1~9的数字恰好每一个出现1次. 暴力破解代码: package lianx ...
- 什么时候css会见less
在一定程度上,css不能被视为一个节目.虽然和其他语言,它有自己的规范.编码,但它的笨拙实在让我失望. 不喜欢css是由于不管怎么优化代码.项目大到一定程序后.都会看上去一团乱.并且有时候一个bug的 ...
- cocos2d-x 3.0rc2 对于每个包执行情况的重要平台 (超级方便)
首先,你需要下载三个文件:每间 android-ndk android-sdk ant 下载位置可以随意:由于3.0rc2执行setup.py 自己主动搜索这三个文件 win32cmd以下: (1) ...
- CentOS修改系统默认语言与编码
有时候在安装CentOS无意中把默认语言设置为中文,而部分SSH软件不支持中文编码,所以在远程管理的时候会出现些乱码的现象. 如何修改CentOS的默认语言呢? 请先使用root权限帐户登陆 一. ...
- Activity中异步操作showDialog异常解决方法:判断Ay是否结束
Android – Displaying Dialogs From Background Threads 判断一下Activity是否在finishing就好了,否则万一Activity销毁了,这个D ...
- 让你在DOS中任意切换目录
尽管Windows图形界面早已经取代了无趣的DOS字符界面(废话,Vista都呼之欲出了),不过在日常操作中,还是有很多时候需要用到命令提示符.比如批量重命名文件时.执行字符命令时.在命令行下恢复系统 ...
- eclipse开发工具Import工程后,工程文件夹上出现黄色感叹号——解决方法
eclipse开发工具Import工程后,工程文件夹上出现黄色感叹号. 可能是Work目录无效,解决方法:删除Work目录即可,如下图所示: 删除后,如下图: