• [ An Ac a Day ^_^ ] hdu 2830 矩阵交换II


    第一眼觉得是个dp 但是有了可以随意交换的条件觉得简单了不少

    但是还是没做出来……

    看了一下别人的做法才觉得自愧不如

    因为所有列都可以随意交换 应该尽量把长的放在一起

    那么将所有的矩形排序之后

    以第j个矩形作为端点的大矩形面积是num[j]*j

    只要从头开始都计算一遍就行了……

    差距好大-_-||

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<algorithm>
     4 #include<cmath>
     5 #include<cstring>
     6 #include<string>
     7 #include<ctime>
     8 #include<map>
     9 #include<set>
    10 #include<vector>
    11 #include<queue>
    12 #include<cstdlib>
    13 #include<cassert>
    14 #include<sstream>
    15 #include<stack>
    16 #include<list>
    17 #include<bitset>
    18 #define cl(a,b) memset(a,b,sizeof(a))
    19 #define debug(x) cerr<<#x<<"=="<<(x)<<endl
    20 using namespace std;
    21 typedef long long ll;
    22 typedef long double ldb;
    23 typedef pair<int,int> pii;
    24 
    25 const int inf=0x3f3f3f3f;
    26 const int maxn=1e9+10;
    27 const int mod=1e7+7;
    28 const double eps=1e-8;
    29 const double pi=acos(-1);
    30 
    31 int dx[8]= {0,0,1,-1,1,-1,1,-1};
    32 int dy[8]= {1,-1,0,0,-1,1,1,-1};
    33 
    34 //---------------------------------------ヽ(^。^)丿
    35 
    36 bool cmp(int a,int b)
    37 {
    38     return a>b;
    39 }
    40 
    41 int main()
    42 {
    43     int n,m;
    44     while(~scanf("%d%d",&n,&m))
    45     {
    46         int ans=0,num[1005],vis[1005];
    47         char str[1005];
    48         cl(vis,0),cl(num,0);
    49         for(int i=0;i<n;i++)
    50         {
    51             scanf("%s",str);
    52             for(int j=0;j<m;j++)
    53             {
    54                 int ok=str[j]-'0';
    55                 if(ok) vis[j]++;
    56                 else vis[j]=0;
    57                 num[j]=vis[j];
    58             }
    59             sort(num,num+m,cmp);
    60             for(int j=0;j<m;j++)
    61                 ans=max(ans,num[j]*(j+1));
    62         }
    63         printf("%d
    ",ans);
    64     }
    65     return 0;
    66 }
    67 /*
    68 
    69 3 4
    70 1011
    71 1001
    72 0001
    73 3 4
    74 1010
    75 1001
    76 0001
    77 
    78 */
  • 相关阅读:
    面试题15:链表中倒数第K个节点
    面试题14:调整数组顺序使奇数位于偶数前面
    面试题13:在O(1)时间删除链表节点
    面试题12:打印1到最大的n位数(大数问题)
    面试题11:数值的整数次方
    面试题10:二进制中1的个数
    面试题9:裴波那切数列
    api_request.go
    string_array.go
    logger.go
  • 原文地址:https://www.cnblogs.com/general10/p/6287582.html
Copyright © 2020-2023  润新知