zoukankan      html  css  js  c++  java
  • 【HDOJ】2830 Matrix Swapping II

    简单DP。

     1 /* 2830 */
     2 #include <iostream>
     3 #include <string>
     4 #include <map>
     5 #include <queue>
     6 #include <set>
     7 #include <stack>
     8 #include <vector>
     9 #include <algorithm>
    10 #include <cstdio>
    11 #include <cmath>
    12 #include <ctime>
    13 #include <cstring>
    14 #include <climits>
    15 #include <cctype>
    16 #include <cassert>
    17 using namespace std;
    18 
    19 const int maxn = 1005;
    20 char M[maxn][maxn];
    21 int mlen[maxn][maxn];
    22 int cnt[maxn];
    23 int n, m;
    24 
    25 int main() {
    26     int i, j, k;
    27     int ans, mx, tmp;
    28     
    29     #ifndef ONLINE_JUDGE
    30         freopen("data.in", "r", stdin);
    31         freopen("data.out", "w", stdout);
    32     #endif
    33     
    34     while (scanf("%d %d", &n, &m) != EOF) {
    35         for (i=1; i<=n; ++i) {
    36             scanf("%s", M[i]+1);
    37             for (j=1; j<=m; ++j)
    38                 M[i][j] -= '0';
    39         }
    40         for (j=1; j<=m; ++j) {
    41             mlen[j][0] = 0;
    42             for (i=1; i<=n; ++i) {
    43                 if (M[i][j])
    44                     mlen[j][i] = mlen[j][i-1]+1;
    45                 else
    46                     mlen[j][i] = 0;
    47             }
    48         }
    49         
    50         ans = 0;
    51         for (i=1; i<=n; ++i) {
    52             memset(cnt, 0, sizeof(cnt));
    53             mx = -1;
    54             for (j=1; j<=m; ++j) {
    55                 ++cnt[mlen[j][i]];
    56                 mx = max(mx, mlen[j][i]);
    57             }
    58             for (j=mx; j>0; --j) {
    59                 ans = max(ans, cnt[j]*j);
    60                 cnt[j-1] += cnt[j];
    61             }
    62         }
    63         printf("%d
    ", ans);
    64     }
    65     
    66     #ifndef ONLINE_JUDGE
    67         printf("time = %d.
    ", (int)clock());
    68     #endif
    69     
    70     return 0;
    71 }
  • 相关阅读:
    hdu 1108 最小公倍数
    hdu 1106 排序
    hdu 1097 A hard puzzle
    hdu 1076 An Easy Task
    hdu 1064 Financial Management
    hdu 1061 Rightmost Digit
    hdu 1050 Moving Tables
    hdu 1060 Leftmost Digit
    hdu 1049 Climbing Worm
    hdu1104
  • 原文地址:https://www.cnblogs.com/bombe1013/p/4455719.html
Copyright © 2011-2022 走看看