Hdu 2830 Matrix Swapping II【思维】

Matrix Swapping II

Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1861    Accepted Submission(s): 1239


Problem Description
Given an N * M matrix with each entry equal to 0 or 1. We can find some rectangles in the matrix whose entries are all 1, and we define the maximum area of such rectangle as this matrix’s goodness. 

We can swap any two columns any times, and we are to make the goodness of the matrix as large as possible.
 

Input
There are several test cases in the input. The first line of each test case contains two integers N and M (1 ≤ N,M ≤ 1000). Then N lines follow, each contains M numbers (0 or 1), indicating the N * M matrix
 

Output
Output one line for each test case, indicating the maximum possible goodness.
 

Sample Input
  
  
3 4 1011 1001 0001 3 4 1010 1001 0001
 

Sample Output
  
  
4 2 Note: Huge Input, scanf() is recommended.

题目大意:

我们可以任意交换两列,我们要找到一个最大面积的矩阵,使得其中所有元素都是1.


思路:


我们处理出以第i行为基础水平线的向下延展的柱形高度(以样例1为基础)sum【i】【j】:

2 0 1 3

1 0 0 2

0 0 0 1

然后我们以每一行为枚举量,去sort这一行的sum【i】【j】(从大到小);

那么ans=max(ans,j*sum【i】【j】);


Ac代码:

#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
char a[1005][1005];
int sum[1005][1005];
int vis[1005];
int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m))
    {
        memset(sum,0,sizeof(sum));
        for(int i=0;i<n;i++)
        {
            scanf("%s",a[i]);
        }
        for(int i=0;i<m;i++)
        {
            for(int j=n-1;j>=0;j--)
            {
                if(a[j][i]=='1')
                {
                    sum[j][i]=sum[j+1][i]+1;
                }
            }
        }
        int output=0;
        for(int i=0;i<n;i++)
        {
            memset(vis,0,sizeof(vis));
            for(int j=0;j<m;j++)
            {
                vis[sum[i][j]]++;
            }
            int tmp=0;
            for(int j=n;j>=1;j--)
            {
                tmp+=vis[j];
                output=max(output,tmp*j);
            }
        }
        printf("%d\n",output);
    }
}




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值