bzoj 1768: [Ceoi2009]logs
2014-10-18 21:39
190 查看
Description
有一个N*M的01矩阵,现在你可以的任意交换其中的列,要求找一个最大的仅由1组成的矩阵。 N<=15000,M<=1500 1 ≤ N ≤ 15000 1 ≤ M ≤ 1500 30% of the test cases will have N,M ≤ 1024Input
N,M 以下N行每行M个字符。Output
Sample Input
10 6001010
111110
011110
111110
011110
111111
110111
110111
000101
010101
Sample Output
21HINT
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; }
相关文章推荐
- BZOJ1768 : [Ceoi2009]logs
- bzoj1768: [Ceoi2009]logs
- BZOJ1767 : [Ceoi2009]harbingers
- BZOJ1766 : [Ceoi2009]photo
- [bzoj1767][Ceoi2009]harbingers【dp】
- bzoj1766: [Ceoi2009]photo
- BZOJ1769 : [Ceoi2009]tri
- bzoj 1767: [Ceoi2009]harbingers
- [Bzoj1767][Ceoi2009]harbingers (树上斜率优化)
- ●BZOJ 1767 [Ceoi2009]harbingers
- bzoj1767[Ceoi2009]harbingers 斜率优化dp
- bzoj 1138: [POI2009]Baj 最短回文路 dp优化
- bzoj1572[Usaco2009 Open]工作安排Job 堆
- [BZOJ1026][SCOI2009]windy数 && 数位DP
- bzoj 1579: [Usaco2009 Feb]Revamping Trails 道路升级——分层图+dijkstra
- bzoj 1433: [ZJOI2009]假期的宿舍
- bzoj 1585: [Usaco2009 Mar]Earthquake Damage 2 地震伤害
- BZOJ 2257 [Jsoi2009]瓶子和燃料 裴蜀定理
- [BZOJ1449][JSOI2009]球队收益(费用流)
- bzoj 1449 [JSOI2009]球队收益(费用拆分,最小费用流)