暴力/DP Codeforces Beta Round #22 (Div. 2 Only) B. Bargaining Table

题目传送门

 1 /*
 2     题意:求最大矩形(全0)的面积
 3     暴力/dp:每对一个0查看它左下的最大矩形面积,更新ans
 4     注意:是字符串,没用空格,好事多磨,WA了多少次才发现:(
 5     详细解释:http://www.cnblogs.com/cszlg/p/3217478.html
 6 */
 7 #include <cstdio>
 8 #include <algorithm>
 9 #include <cstring>
10 #include <cmath>
11 using namespace std;
12
13 const int MAXN = 33;
14 const int INF = 0x3f3f3f3f;
15 char s[MAXN][MAXN];
16 int n, m;
17
18 int get_sum(int x, int y)
19 {
20     int res = 0;    int d, w = 30;
21     for (int i=x; i<n; ++i)
22     {
23         if (s[i][y] == ‘1‘)    break;
24         int j = y + 1;
25         while (j < m && s[i][j] == ‘0‘)    ++j;
26         d = i - x + 1;
27         if (w > j - y)    w = j - y;
28         res = max (res, (w + d) * 2);
29     }
30
31     return res;
32 }
33
34 int main(void)        //Codeforces Beta Round #22 (Div. 2 Only) B. Bargaining Table
35 {
36     while (scanf ("%d%d", &n, &m) == 2)
37     {
38         for (int i=0; i<n; ++i)
39         {
40             scanf ("%s", s[i]);
41         }
42
43         int ans = 0;
44         for (int i=0; i<n; ++i)
45         {
46             for (int j=0; j<m; ++j)
47             {
48                 if (s[i][j] == ‘0‘)
49                 {
50                     ans = max (ans, get_sum (i, j));
51                 }
52             }
53         }
54
55         printf ("%d\n", ans);
56     }
57
58     return 0;
59 }
时间: 2024-10-13 12:34:55

暴力/DP Codeforces Beta Round #22 (Div. 2 Only) B. Bargaining Table的相关文章

Codeforces Beta Round #22 (Div. 2 Only)

Codeforces Beta Round #22 (Div. 2 Only) http://codeforces.com/contest/22 A 水题 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define maxn 500005 7 t

图论/暴力 Codeforces Beta Round #94 (Div. 2 Only) B. Students and Shoelaces

题目传送门 1 /* 2 图论/暴力:这是个连通的问题,每一次把所有度数为1的砍掉,把连接的点再砍掉,总之很神奇,不懂:) 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <algorithm> 7 #include <cmath> 8 using namespace std; 9 10 const int MAXN = 1e2 + 10; 11 const int INF = 0x3f3f3

Codeforces Beta Round #31 (Div. 2, Codeforces format)

Codeforces Beta Round #31 (Div. 2, Codeforces format) http://codeforces.com/contest/31 A 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb p

Codeforces Beta Round #59 (Div. 2)

Codeforces Beta Round #59 (Div. 2) http://codeforces.com/contest/63 A 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define pb push_back 7 #define

Codeforces Beta Round #91 (Div. 1 Only) E. Lucky Array

E. Lucky Array Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467are not. Petya has an arra

Codeforces Beta Round #6 (Div. 2 Only)

Codeforces Beta Round #6 (Div. 2 Only) A 水题 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define maxn 1000010 7 typedef long long ll; 8 /*#ifndef

Codeforces Beta Round #9 (Div. 2 Only)

Codeforces Beta Round #9 (Div. 2 Only) http://codeforces.com/contest/9 A gcd水题 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define maxn 1000010 7

Codeforces Beta Round #14 (Div. 2)

Codeforces Beta Round #14 (Div. 2) http://codeforces.com/contest/14 A 找最大最小的行列值即可 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define maxn 500005

Codeforces Beta Round #25 (Div. 2 Only)

Codeforces Beta Round #25 (Div. 2 Only) http://codeforces.com/contest/25 A 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 #define maxn 500005 7 type