USACO 5.3 Big Barn(DP)

最大子矩阵问题,USACO上貌似好几个把。。

 1 /*
 2 ID: cuizhe
 3 LANG: C++
 4 TASK: bigbrn
 5 */
 6 #include <iostream>
 7 #include <cstring>
 8 #include <cstdio>
 9 #include <cstdlib>
10 using namespace std;
11 int dp[1001][1001],r[1001][1001],c[1001][1001];
12 bool o[1001][1001];
13 int main()
14 {
15     int n,m,x,y,maxz,i,j;
16     freopen("bigbrn.in","r",stdin);
17     freopen("bigbrn.out","w",stdout);
18     scanf("%d%d",&n,&m);
19     for(i = 1;i <= m;i ++)
20     {
21         scanf("%d%d",&x,&y);
22         o[x][y] = 1;
23     }
24     for(x = 1;x <= n;x ++)
25     {
26         for(y = 1;y <= n;y ++)
27         {
28             if(o[x][y])
29             {
30                 r[x][y] = 0;
31                 c[x][y] = 0;
32                 dp[x][y] = 0;
33             }
34             else
35             {
36                 r[x][y] = r[x-1][y] + 1;
37                 c[x][y] = c[x][y-1] + 1;
38                 dp[x][y] = min(min(r[x][y],c[x][y]),dp[x-1][y-1]+1);
39             }
40         }
41     }
42     maxz = 0;
43     for(i = 1;i <= n;i ++)
44     {
45         for(j = 1;j <= n;j ++)
46         {
47             maxz =max(dp[i][j],maxz);
48         }
49     }
50     printf("%d\n",maxz);
51     return 0;
52 }

 

转载于:https://www.cnblogs.com/naix-x/archive/2013/05/27/3102051.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值