Loading

HDU 2830:Matrix Swapping II(思维)

http://acm.hdu.edu.cn/showproblem.php?pid=2830

题意:……

思路:对于每一列,它是固定的,用dp[][]处理出连续的长度。例如:

假设我们扫第四列的时候,我们可以知道 i = 4,j = 1这个位置是4,那么它上面是有3个连续的1,因此它的面积可以是4 * 1, i = 4, j = 2的时候,因为刚才左边肯定大于等于现在的值,那么目前的面积可以是3 * 2,以此类推。

图: 1 1 0 0         DP数组:  1 1 0 0         排序后:   1 1 0 0

       0 1 1 1                       0 2 1 1                        2 1 1 0

       1 1 1 1                       1 3 2 2                        3 2 2 1

       0 1 1 0                       0 4 3 0                        4 3 0 0

 

 1 #include <cstdio>
 2 #include <algorithm>
 3 #include <iostream>
 4 #include <cstring>
 5 #include <string>
 6 #include <cmath>
 7 #include <queue>
 8 #include <vector>
 9 #include <map>
10 #include <set>
11 #include <stack>
12 using namespace std;
13 #define INF 0x3f3f3f3f
14 #define N 100010
15 typedef long long LL;
16 int dp[1010][1010];
17 char mp[1010][1010];
18 bool cmp(const int &a, const int &b) { return a > b; }
19 
20 int main() {
21     int n, m;
22     while(~scanf("%d%d", &n, &m)) {
23         for(int i = 1; i <= n; i++) scanf("%s", 1 + mp[i]);
24         memset(dp, 0, sizeof(dp));
25         for(int i = 1; i <= n; i++)
26             for(int j = 1; j <= m; j++)
27                 if(mp[i][j] == '1')
28                     dp[i][j] = dp[i-1][j] + 1;
29         int ans = 0;
30         for(int i = 1; i <= n; i++) {
31             sort(dp[i] + 1, dp[i] + 1 + m, cmp);
32             for(int j = 1; j <= m; j++)
33                 ans = max(ans, dp[i][j] * j);
34         }
35         printf("%d\n", ans);
36     }
37     return 0;
38 }

 

posted @ 2017-01-15 21:21  Shadowdsp  阅读(225)  评论(0编辑  收藏  举报