【链接】 我是链接,点我呀:)

【题意】

如果任意行之间可以重新排序。
问你最大的全是1的子矩阵中1的个数

【题解】

设cnt[i][j]
表示(i,j)这个点往右连续的1的个数
我们枚举列j
然后对于第j列的cnt[1..n][j]
我们把这n个数字排个序(升序)
然后顺序枚举这n个数字
假设我们枚举到了第i个数字,显然第i~n这n-i+1个数字是能组成一个宽为cnt[i][j]长为n-i+1的矩形的
且这些矩形的左边界都是i
这就是这道题的技巧所在了
找到最短的宽度,让比它长的都和它适应
秒啊

【代码】

import java.io.*;
import java.util.*; public class Main { static InputReader in;
static PrintWriter out; public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
} static int N = (int)5000;
static class Task{ int n,m;
String s[] = new String[N+10];
int cnt[][] = new int[N+10][N+10];
int col[][] = new int[N+10][N+10]; public void solve(InputReader in,PrintWriter out) {
n = in.nextInt();m = in.nextInt();
for (int i = 1;i <= n;i++) {
s[i] = in.next();
StringBuilder sb = new StringBuilder(s[i]);
sb.insert(0, ' ');
s[i] = sb.toString();
}
for (int i = 1;i <= n;i++) {
for (int j = m;j >= 1;j--) {
if (s[i].charAt(j)=='0') {
cnt[i][j] = 0;
}else {
cnt[i][j] = cnt[i][j+1]+1;
} }
} for (int j = m;j >= 1;j--) {
for (int i = 1;i <= n;i++)
{
col[j][i] = cnt[i][j];
}
} long ans = 0;
for (int i = 1;i <= m;i++) {
Arrays.sort(col[i],1,n+1);
for (int j = 1;j <= n;j++) {
ans = Math.max(ans,col[i][j]*(n-j+1));
}
}
out.println(ans);
}
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
} public long nextLong() {
return Long.parseLong(next());
}
}
}

【Codeforces 375B】Maximum Submatrix 2的更多相关文章

  1. 【codeforces 509A】Maximum in Table

    [题目链接]:http://codeforces.com/contest/509/problem/A [题意] 给你一个递推式f[i][j] = f[i-1][j]+f[i][j-1]; 让你求f[i ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【39.66%】【codeforces 740C】Alyona and mex

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【81.82%】【codeforces 740B】Alyona and flowers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【35.29%】【codeforces 557C】Arthur and Table

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【23.33%】【codeforces 557B】Pasha and Tea

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【55.70%】【codeforces 557A】Ilya and Diplomas

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  8. 【36.86%】【codeforces 558B】Amr and The Large Array

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【24.17%】【codeforces 721D】Maxim and Array

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. C#面向过程项目之飞行棋

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 飞行棋V ...

  2. 02_cfork分叉进程

    fork函数.调用它就可以在当前的进程当中给它分叉出一个新的进程.分叉出的进程就可以看看它有什么特点?

  3. E20180113-hm

    round robin algorithm  轮询调度算法 circular  adj. 圆形的; 环行的; 迂回的,绕行的; 供传阅的,流通的;

  4. springboot(三)配置日志

    github代码:https://github.com/showkawa/springBoot_2017/tree/master/spb-demo/spb-brian-query-serviceSLF ...

  5. [读书笔记3]《C语言嵌入式系统编程修炼》

    第五章 性能优化   5.1 使用宏定义 在C语言中,宏是产生内嵌代码的唯一方法.对于嵌入式系统而言,为了能达到性能要求,宏是一种很好的代替函数的方法.   写一个"标准"宏MIN ...

  6. 关于sql的case when用法简述

    刚入手公司项目,需要添加一个功能,用到了SQL的case when以及concat SELECT eve.cc, eve.sc, case concat(cc,sc) ' THEN '' ' THEN ...

  7. 解决Unicode编码(&#29848;)

    随着互联网发展,B/S越来越受欢迎 Code编码格式也越来载多, 在大千花花世界 中文在Web显示看似一样但实际编码并不样,导致从页面获取的资料录入到数据库中时 存取的就是Code编码 如:Unico ...

  8. SAS进阶《深入分析SAS》之数据汇总和展现

    SAS进阶<深入分析SAS>之数据汇总和展现 1. 通过Print过程制作报表 proc print <data=数据集>; run; 选项: obs=修改观测序号列标签 no ...

  9. Android开发: 关于性能需要考虑的

    刚做Android开发时,只管完成任务,将需求完成,以能完成一款界面酷炫的app为自豪.然而,随着代码量的增加,越来越意识到,一款成功的移动端产品,光有酷炫的外衣还不够,还需要在各方面都优秀. 试想, ...

  10. taskctl命令行类(sh、exe、python新增scp)插件升级扩展

    转载自: http://www.taskctl.com/forum/detail_129.html 上次写了一个帖子 TASKCTL中不使用代理,通过ssh免密连接执行远程脚本配置(SSH插件扩展)h ...