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

【题意】

如果任意行之间可以重新排序。
问你最大的全是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. SQLAlchemy 反向生成 model 模型

    前言 Django 反向生成的 model 模型的命令 :  python manager.py inspectdb SQLAlchemy / Flask-SQLAlchemy则是: pip3 ins ...

  2. Linux下 CentOS 7 对比6 改动详解 及 系统安装

    系统基础服务变化 操作系统 本文CentOS7 为最新版7.5 本文CentOS6 为6.9 操作 Centos6 Centos7 对比 自动补全 只支持命令.文件名 支持命令.选项.文件名 文件系统 ...

  3. bzoj1052覆盖问题(二分+贪心)

    1052: [HAOI2007]覆盖问题 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2446  Solved: 1131[Submit][Stat ...

  4. spring 异常处理

    1. 实现接口 HandlerExceptionResolver 捕获异常 2.@ExceptionHandler 在方法添加注解,捕获本地controller异常 3.@ControllerAdvi ...

  5. [C和指针] 1-快速上手、2-基本概念、3-数据

    第1章 快速上手 1.1.1 空白和注释   程序的空白的作用: 空行将程序的不同部分分割开来:制表符缩进语句,可以更好地显示程序的结构等等.     软件最大的开销并非在于编写,而是在于维护,所以需 ...

  6. 题解报告:hdu 2717 Catch That Cow(bfs)

    Problem Description Farmer John has been informed of the location of a fugitive cow and wants to cat ...

  7. Oracle 参考脚本

    一.创建物化视图 --新建表空间 CREATE TABLESPACE MLOG_TBS LOGGING DATAFILE 'mlog_tbs.dbf' SIZE 32M AUTOEXTEND ON N ...

  8. 282 Expression Add Operators 给表达式添加运算符

    给定一个仅包含0-9的字符串和一个目标值,返回在数字之间添加了二元运算符(不是一元的) +.-或*之后所有能得到目标值的情况.例如:"123", 6 -> ["1+ ...

  9. C#基础 out传值

    public void Out(out int a, out int b) {//out相当于return返回值 //可以返回多个值 //拿过来变量名的时候,里面默认为空值 a=1; b=2; } s ...

  10. Xcode 动态库及Framework 安装路径设置

    使用Xcode开发动态库及Framework时,需要为其设置Install path.在设置Install path时,可能会使用到以下几个路径: 1)绝对路径:               绝对路径 ...