bzoj 1768: [Ceoi2009]logs

Description

有一个N*M的01矩阵,现在你可以的任意交换其中的列,要求找一个最大的仅由1组成的矩阵。 N<=15000,M<=1500 1 ≤ N ≤ 15000 1 ≤ M ≤ 1500 30% of the test cases will have N,M ≤ 1024

Input

N,M 以下N行每行M个字符。

Output

Sample Input

10 6
001010
111110
011110
111110
011110
111111
110111
110111
000101
010101

Sample Output

21

HINT

By permuting the columns such that columns 2, 
4 and 5 are adjacent you have a rectangle of area 

21 (rows 2-8 and columns 2, 4, 5). 


ceoi是中欧么...连题解都只有一篇还看不太懂

http://blog.sina.com.cn/s/blog_7cd3ac450100skzu.html

我们用f[i][j]表示该列最多向下延伸的长度。

若s[i][j]=0 则f[i][j]=0,否则f[i][j]=f[i-1][j]+1 【因为统一列的顺序不变】

然后用t[i]表示横向最多延伸的长度,q数组记录1的位置

然后因为内存只有64M所以要滚动数组

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
using namespace std;
int i,j,n,ans,l,r,m;
string s;
int f[2][1501],q[2][1501];
bool d[2][1501];
int t[2];
int main()
{
     scanf("%d%d",&n,&m);
     for(i=1;i<=n;i++)
     {
          l=i&1;
		  r=(i+1)&1;
		  t[l]=0;
		  cin>>s;
          for(j=1;j<=m;j++)
          {
               if(s[j-1]=='1')
               {
                    d[l][j]=true;
                    if(!d[r][j])
                    {
                         t[r]++;
                         q[r][t[r]]=j;
                         f[l][j]=1;
                    }
					else
					     f[l][j]=f[r][j]+1;
			   }
               else
               {
                    d[l][j]=false;
					f[l][j]=0;
			   }
          }
          for(j=1;j<=t[r];j++)
          {
               if(d[l][q[r][j]])
               {
                    t[l]++;
                    q[l][t[l]]=q[r][j];
                    if(f[l][q[r][j]]*t[l]>ans)
					     ans=f[l][q[r][j]]*t[l];
               }
          }
     }
     printf("%d\n",ans);
     return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值