Analysis: Scan each row, use this row as the base, use dp to store the heights reached by column 1, and then sort the heights (of course, you cannot sort the heights directly by dp, because it is useful to scan the next line), it is easy to find the largest area. finally, we can find the overall maximum value!
[Cpp]
# Include <iostream>
# Include <string>
# Include <cstring>
# Include <algorithm>
Using namespace std;
Const int maxn = 1005;
Int work (int g [], int m ){
Int dp [maxn];
For (int I = 0; I <m; ++ I) dp [I] = g [I];
Sort (dp, dp + m );
Int ret = 0;
For (int I = m-1; I> = 0; -- I)
Ret = max (ret, dp [I] * (m-I ));
Return ret;
}
Int main (){
Int n, m;
While (cin> n> m ){
String map [maxn];
For (int I = 0; I <n; ++ I)
Cin> map [I];
Int dp [maxn]; // storage height
Int ans = 0;
Memset (dp, 0, sizeof (dp ));
For (int I = 0; I <n; ++ I ){
For (int j = 0; j <m; ++ j)
If (map [I] [j] = '1') dp [j] ++;
Else dp [j] = 0;
Ans = max (ans, work (dp, m ));
}
Cout <ans <endl;
}
Return 0;
}
# Include <iostream>
# Include <string>
# Include <cstring>
# Include <algorithm>
Using namespace std;
Const int maxn = 1005;
Int work (int g [], int m ){
Int dp [maxn];
For (int I = 0; I <m; ++ I) dp [I] = g [I];
Sort (dp, dp + m );
Int ret = 0;
For (int I = m-1; I> = 0; -- I)
Ret = max (ret, dp [I] * (m-I ));
Return ret;
}
Int main (){
Int n, m;
While (cin> n> m ){
String map [maxn];
For (int I = 0; I <n; ++ I)
Cin> map [I];
Int dp [maxn]; // storage height
Int ans = 0;
Memset (dp, 0, sizeof (dp ));
For (int I = 0; I <n; ++ I ){
For (int j = 0; j <m; ++ j)
If (map [I] [j] = '1') dp [j] ++;
Else dp [j] = 0;
Ans = max (ans, work (dp, m ));
}
Cout <ans <endl;
}
Return 0;
}