uva 10074 Take the Land

原题:
The poor man went to the King and said, “Lord, I cannot maintain my family. Please give me some wealth so that I can survive with my wife and children.” The King replied, “I shall grant you a piece of land so that you can cultivate and grow food for your family. In the southern part of the Kingdom there is a rectangular forest. Trees have been planted there at regular intervals. Some of the trees have been cut for use. You are allowed to take any rectangular piece of land that does not contain any tree.
You need not go to the forest to select the piece of land. I have a map containing 1’s at places where there is a tree and 0s at points where the tree has been cut.”
Help the poor man to find out the largest piece of land. Area of the land is measured in units of number of trees that were there. Your program should take a matrix of 1’s and 0’s as input and output the area of the largest rectangular piece of land that contain no tree. Be careful about the efficiency of your program.
Input
The input file may contain multiple test cases. The first line of each test case contains two integers M and N (1 ≤ M,N ≤ 100) giving the number of rows and columns in the matrix that follows. Each of the next M lines contains N symbols (either ‘0’ or ‘1’). Two consecutive symbols in a line will be separated by a single space. The input terminates with two zeros for M and N.
Output
For each test case in the input print a line giving the area (in terms of the number of trees were there) of the largest rectangular piece of land containing no tree.

Sample Input
6 7
0 1 1 0 1 1 0
0 0 0 0 0 1 0
1 0 0 0 0 0 1
0 1 0 0 0 0 1
1 1 0 0 0 1 0
1 1 0 1 1 0 0
0 0
Sample Output
12

中文

给你一个矩阵,让你算最大0的面积

#include<bits/stdc++.h>
using namespace std;
int dp[101][101];
int sum[101][101];
int main()
{
    ios::sync_with_stdio(false);
    int t;
    int row,col;
    while(cin>>row>>col,row+col)
    {
        string s;
        memset(dp,0,sizeof(dp));
        for(int i=1;i<=row;i++)
        {
            for(int j=1;j<=col;j++)
            {
                int tmp;
                cin>>tmp;
                if(tmp)
                    sum[i][j]=0;
                else
                    sum[i][j]=1;
            }
        }
        for(int i=1;i<row;i++)
        {
            for(int j=1;j<=col;j++)
            {
                if(sum[i+1][j]==1)
                {
                    sum[i+1][j]=sum[i][j]+1;
                }
            }
        }
        int ans=0;
        for(int i=1;i<=row;i++)
        {
            for(int j=1;j<=col;j++)
            {
                int width=1;
                for(int left=j-1;;left--)
                {
                    if(j==0)
                        break;
                    if(sum[i][left]<sum[i][j])
                        break;
                    else
                        width++;
                }
                for(int right=j+1;;right++)
                {
                    if(right==col+1)
                        break;
                    if(sum[i][right]<sum[i][j])
                        break;
                    else
                        width++;
                }
                dp[i][j]=sum[i][j]*width;
                ans=max(dp[i][j],ans);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

思路
和uva 836一个问题,只不过这道题输入方式比较人性化
算是买一赠一的问题 哈哈

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值