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.
 
Source

题意:一列一列的移动图,问最大的1组成的面积?

思路:每一行中。对高排序。高就是a【i】。长就是i。我代码中是j,然后就能够求最优解了

</pre><pre name="code" class="cpp">#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std; #define N 1005 int h[N],a[N];
int n,m; int cmp(int a,int b)
{
return a>b;
} int main()
{
int i,j;
char c; while(~scanf("%d%d",&n,&m))
{
getchar();
memset(h,0,sizeof(h)); int ans=0; for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
scanf("%c",&c);
if(c=='1')
h[j]++;
else
h[j]=0;
}
getchar(); for(j=1;j<=m;j++)
a[j]=h[j]; sort(a+1,a+m+1,cmp); //强调一次,是一列一列的移动 for(j=1;j<=m;j++)
ans=max(ans,a[j]*j);
}
printf("%d\n",ans);
}
return 0;
}

HDu 2830 Matrix Swapping II(dp)的更多相关文章

  1. hdu 2830 Matrix Swapping II(额,,排序?)

    题意: N*M的矩阵,每个格中不是0就是1. 可以任意交换某两列.最后得到一个新矩阵. 问可以得到的最大的子矩形面积是多少(这个子矩形必须全是1). 思路: 先统计,a[i][j]记录从第i行第j列格 ...

  2. HDU 2830 Matrix Swapping II (预处理的线性dp)

    Matrix Swapping II Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  3. HDU 2639 Bone Collector II (dp)

    题目链接 Problem Description The title of this problem is familiar,isn't it?yeah,if you had took part in ...

  4. HDU 2830:Matrix Swapping II(思维)

    http://acm.hdu.edu.cn/showproblem.php?pid=2830 题意:-- 思路:对于每一列,它是固定的,用dp[][]处理出连续的长度.例如: 假设我们扫第四列的时候, ...

  5. HDU 2830 Matrix Swapping II

    给一个矩阵,依然是求满足条件的最大子矩阵 不过题目中说任意两列可以交换,这是对题目的简化 求出h数组以后直接排序,然后找出(col-j)*h[j]的最大值即可(这里的j是从0开始) 因为排序会影响到h ...

  6. Matrix Swapping II(求矩阵最大面积,dp)

    Matrix Swapping II Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  7. HDU 1864 最大报销额(DP)

    题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1864 题目: 最大报销额 Time Limit: 1000/1000 MS (Java/Others) ...

  8. HDU 4562 守护雅典娜(dp)

    守护雅典娜 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submi ...

  9. HDU - 6199 gems gems gems (DP)

    有n(2e4)个宝石两个人轮流从左侧取宝石,Alice先手,首轮取1个或2个宝石,如果上一轮取了k个宝石,则这一轮只能取k或k+1个宝石.一旦不能再取宝石就结束.双方都希望自己拿到的宝石数比对方尽可能 ...

随机推荐

  1. 关于在打包Jar文件时遇到的资源路径问题(二)

    在关于<关于在打包Jar文件时遇到的资源路径问题(一)>中,以及描述了当资源与可执行JAr分离时的资源路径代码的编写问题,后来想了想,为什么将<Java核心技术卷一>中的程序1 ...

  2. LLBL Gen Pro 5.0

    LLBL Gen Pro 5.0 企业应用开发入门 Solutions Design 公司于2016年5月发布了LLBL Gen Pro 5.0,这个新版本的发布出乎于我的意料.我的猜想是从4.2升级 ...

  3. 初识JAVA,对servlet的理解

    一.WEB开发的简单理解 Web开发是一个指代网页或站点编写过程的广义术语.网页使用 HTML.CSS 和 JavaScript编写.这些页面可能是类似于文档的简单文本和图形.页面也能够是交互式的,或 ...

  4. hdu 4550 贪婪 思考题 权

    http://acm.hdu.edu.cn/showproblem.php?pid=4550 想了挺久,然后各种分类 最终AC,假设是现场,对自己没信心的话,预计还是要WA,,,,,,然后搜题解,发现 ...

  5. 一起talk C栗子吧(第十二回:C语言实例--单链表一)

    各位看官们,大家好.从今天開始,我们讲大型章回体科技小说 :C栗子.也就是C语言实例.闲话休提, 言归正转. 让我们一起talk C栗子吧! 看官们,上一回中咱们没有说详细的样例,并且是说了样例中的文 ...

  6. VMWARE安装MAC时无法移动鼠标?

    1.先不要怀疑你的软件 2.查看你的硬件设置 3.什么?你把USB去除了? 4.给我加回来!!! 5.OK!鼠标可以移动了!

  7. cannot run program "git.exe":CreateProcess error=2

    在使用android studio从git上check项目的时候报错cannot run program "git.exe":CreateProcess error=2 请检查下面 ...

  8. Common lisp菜鸟指南(译)

    Common lisp菜鸟指南(译) Common lisp菜鸟指南(译)

  9. SLIC superpixel实现分析

    http://infoscience.epfl.ch/record/149300这是SLIC算法的官网,网站有和SLIC相关的资源. SLIC主要运用K-means聚类算法进行超像素的处理,聚类算法中 ...

  10. Qt中提高sqlite的读写速度(使用事务一次性写入100万条数据)

    SQLite数据库本质上来讲就是一个磁盘上的文件,所以一切的数据库操作其实都会转化为对文件的操作,而频繁的文件操作将会是一个很好时的过程,会极大地影响数据库存取的速度.例如:向数据库中插入100万条数 ...