Codeforces Round #221 (Div. 2) D. Maximum Submatrix 2 (thinking question ),

Source: Internet
Author: User

Codeforces Round #221 (Div. 2) D. Maximum Submatrix 2 (thinking question ),

Question address: codeforces 221 D
This is the first question of D in CF in our life. (At that time, only question A was made ..) When I reviewed the Chinese New Year, I took a few D questions by the way. Currently, the question "D" of CF cannot be done during the competition. However, you can do it yourself after the game. It is said that if question D can stabilize in the competition, it will be able to compete in the regional silver. So we strive for four questions in the future.
This question should not be labeled at the beginning .. It is DP .. So I keep thinking in the DP direction. But it does not feel like DP. I changed my mind and made it.
The general method is to pre-process the maximum number of consecutive 1 Numbers extending to the left of each row. Then sort each row (hash is used here, and the speed is faster). The current area is calculated from the largest to the smallest and the maximum value is obtained.
The Code is as follows:

#include <iostream>#include <string.h>#include <math.h>#include <queue>#include <algorithm>#include <stdlib.h>#include <map>#include <set>#include <stdio.h>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")#define LL __int64#define pi acos(-1.0)const int mod=1e9+7;const int INF=0x3f3f3f3f;const double eqs=1e-9;int dp[5002], mark[5002][5002];char s[5002];int main(){        int n, m, i, j, max1, tmp;        while(scanf("%d%d",&n,&m)!=EOF){                memset(mark,0,sizeof(mark));                getchar();                for(i=0;i<n;i++){                        gets(s);                        dp[0]=0;                        for(j=1;j<=m;j++){                                if(s[j-1]=='1') {                                                dp[j]=dp[j-1]+1;                                                mark[j][dp[j]]++;                                }                                else dp[j]=0;                        }                }                max1=0;                for(j=1;j<=m;j++){                        tmp=0;                        for(i=m;i>=1;i--){                                if(!mark[j][i]) continue ;                                tmp+=mark[j][i];                                max1=max(max1,tmp*i);                        }                }                printf("%d\n",max1);        }        return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.