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)。

-------------------------------------------------------------------------------

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define rep(i,r) for(int i=0;i<r;i++)
#define clr(x,c) memset(x,c,sizeof(x))
#define Rep(i,l,r) for(int i=l;i<r;i++)
using namespace std;
const int maxn=1000+5;
int d[maxn][maxn];
int ok[maxn][maxn];
int n;
int dp(int i,int j) {
int &ans=d[i][j];
if(ans>=0) return ans;
ans=0;
if(!ok[i][j]) return ans;
if(i==n-1 || j==n-1) return ans=1;
return ans=min(dp(i+1,j+1),min(dp(i+1,j),dp(i,j+1)))+1;
}
int main()
{
freopen("bigbrn.in","r",stdin);
freopen("bigbrn.out","w",stdout);
clr(ok,-1);
int t;
cin>>n>>t;
rep(i,t) {
int a,b;
scanf("%d%d",&a,&b);
ok[--a][--b]=0;
}
clr(d,-1);
int ans=0;
rep(i,n)
   rep(j,n) ans=max(ans,dp(i,j));
   
cout<<ans<<endl;
return 0;
}

-------------------------------------------------------------------------------

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)的更多相关文章

  1. USACO Section 5.3 Milk Measuring (IDDFS+dp)

    迭代加深搜索,从小到大枚举桶数的上限maxd:对每个maxd,枚举每个组合,判断是否能够倒出q:直到得到answer.判断的部分就用dp(完全背包). ------------------------ ...

  2. USACO Section 1.3 Barn Repair 解题报告

    题目 题目描述 某农夫有一个养牛场,所有的牛圈都相邻的排成一排(共有S个牛圈),每个牛圈里面最多只圈养一头牛.有一天狂风卷积着乌云,电闪雷鸣,把牛圈的门给刮走了.幸运的是,有些牛因为放假,所以没在自己 ...

  3. [USACO Section 5.3]量取牛奶 Milk Measuring (动态规划,背包$dp$)

    题目链接 Solution 完全背包 \(dp\) , 同时再加一个数组 \(v[i][j]\) 记录当总和为\(j\) 时第 \(i\) 种物品是否被选. 为保证从小到大和字典序,先将瓶子按大小排序 ...

  4. 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&& ...

  5. USACO 6.1 A Rectangular Barn

    A Rectangular Barn Mircea Pasoi -- 2003 Ever the capitalist, Farmer John wants to extend his milking ...

  6. 【USACO 2.2】Subset Sums (DP)

    N (1 <= N <= 39),问有多少种把1到N划分为两个集合的方法使得两个集合的和相等. 如果总和为奇数,那么就是0种划分方案.否则用dp做. dp[i][j]表示前 i 个数划分到 ...

  7. 【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位 ...

  8. USACO Section 3.3 商店购物 Shopping Offers

    题目背景 在商店中,每一种商品都有一个价格(用整数表示).例如,一朵花的价格是 2 zorkmids (z),而一个花瓶的价格是 5z .为了吸引更多的顾客,商店举行了促销活动. 题目描述 促销活动把 ...

  9. USACO Section 3.2 01串 Stringsobits

    题目背景 考虑排好序的N(N<=31)位二进制数. 题目描述 他们是排列好的,而且包含所有长度为N且这个二进制数中1的位数的个数小于等于L(L<=N)的数. 你的任务是输出第i(1< ...

随机推荐

  1. Unix/Linux环境C编程入门教程(13) 开发环境搭建VMware软件安装

    VMware(中文名威睿",纽约证券交易所"代码:VMW) 虚拟机软件,是全球桌面到数据中心虚拟化解决方案的领导厂商.全球不同规模的客户依靠VMware来降低成本和运营费用.确保业 ...

  2. Linux-VPN安装配置方法

    VNP服务器IP地址为:192.168.6.6 一.编译安装:   注意:可能需要ppp.libcap.libcap-devel ncurses-devel RPM 包支持,如果没有请安装 libca ...

  3. 前端开发工具—fiddle

  4. C#实现给手机发送短信

    public static void SendSMS(string FaSongUser, string ToUserList, string ContentStr)    {        //针对 ...

  5. MySQL学习笔记(4)

    插入记录① INSERT [INTO] tbl_name [(col_name,-)] {VALUES | VALUE} ({expr | DEFAULT},-),(-),- 可以用表达式或者DEFA ...

  6. IIS7.5(IIS7)配置伪静态urlrewrite

    找了好久,终于找到了.已经测试通过,收藏. 转载自:http://jingyan.baidu.com/article/67508eb4ff92c69cca1ce49a.html 首先新建一个应用程序池 ...

  7. IOS开发-UIView之动画效果的实现方法(合集)

    http://www.cnblogs.com/GarveyCalvin/p/4193963.html 前言:在开发APP中,我们会经常使用到动画效果.使用动画可以让我们的APP更酷更炫,最重要的是优化 ...

  8. SQL Server中 sysobjects、syscolumns、systypes

    1.sysobjects    系统对象表. 保存当前数据库的对象,如约束.默认值.日志.规则.存储过程等 在大多数情况下,对你最有用的两个列是Sysobjects.name和Sysobjects.x ...

  9. 如何为你的美术妹子做Unity的小工具(一)

    在上的工具栏添加   也就是这个位置

  10. js点击事件代理时切换图片如何防抖动

    由于图片的加载速度比较慢,我们可以直接用64base对图片进行编码,把编码加在图片的url中~~~这样加载会快一些,也不会有切换图片时出现的抖动效果