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. RAID详细介绍

    RAID详细介绍 RAID 0 又称为Stripe或Striping,它代表了所有RAID级别中最高的存储性能.RAID 0提高存储性能的原理是把连续的数据分散到多个磁盘上存取,这样,系统有数据请求就 ...

  2. 如何在IE8下调试OCX控件

    第一种方式 多进程模式下, 在IE8打开web页面, 然后在调试菜单选择附加到进程, 这时看到2个IE进程, 选择没有带标题的, 也就是主进程, 就可以正常调试了. 此方式比较麻烦, 不能F5直接启动 ...

  3. 2016 Multi-University Training Contest 3 总结

    又是多校总结时间. 这两天重感冒,精神不佳,总结一拖再拖,结果到了多校第四场结束后回来总结第三场.不过因为还在补第三场的题,所以还是记得挺清楚的 欣君说决定自己AFK试试,于是全程读题算公式. 欣君翻 ...

  4. iOS获取手机当前的网络状态

    获取iOS网络状态,目前有两个办法. 1.通过监听手机状态栏的信息. 2.通过使用官方提供的类Reachability. 一.通过手机监听手机状态栏的信息 好处: 1.可以通过苹果的审核上架AppSt ...

  5. Android Popupwindow 拖动

    版本号:1.0 日期:2014.4.29 版权:© 2014 kince 转载注明出处 关于View的拖动大家应该比較了解了,比方对一个控件IamgeView拖动,或者一个视图View拖动,实现方式也 ...

  6. NET,ASP.NET,C#,WinFrom之间的联系与区别

    1:C#是编程语言(静态,强类型).类似中文.德文.英文这样. 2:.NET是一个平台(可承载多个编程语言,比如C# C++.net J# VB.Net),       但是都是运行在.net Fra ...

  7. SQL Server中 sysobjects、syscolumns、systypes

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

  8. 关于 android Intent 传对象和对象数组的一些操作

    直接开正题,Intent传递值就是平常那些很简单的,接下来介绍传递 对象,和 对象数组 1 .intent 传递自定义的 对象 - 实体类继承  Serializable public class A ...

  9. C++から広がり

    泛型编程(Generic Programming)最初提出时的动机很简单直接:发明一种语言机制,能够帮助实现一个通用的标准容器库.所谓通用的标准容器库,就是要能够做到,比如用一个List类存放所有可能 ...

  10. 0622 python 基础05

    使用双重for循环,打印 0~100 # -*- coding: utf-8 -*- # D:\python\test.py def printOneToHundred():     for i in ...