Http://codeforces.com/contest/1060/problem/C
Test instructions
The length of a and B arrays is n, M, respectively. Matrix C,CIJ=AI*BJ. In C, find a sub-matrix, the sub-matrix of all elements and not less than X, the maximum area of such a sub-matrix.
Ideas:
1, the matrix element and converted to (AI+......+AJ) * (BK+......+BL) Form, that is, a continuous element in a array and multiplied by the B array of successive elements and.
2, because only asked to find the maximum area, so long and wide starting point of the location of any arbitrary, so just a, b array of all the continuous length of the smallest element and (example, A's length of 5 continuous segment element and the minimum value)
Finally, the length and width of the sub-matrices are enumerated in sequence.
#include <cstdio>#include<iostream>using namespacestd;#defineLL Long LongintMain () {LL x; intn,m,num1[2005],num2[2005]; intsub1[2005],sub2[2005],sum1[2005],sum2[2005]; sum1[0]=sum2[0]=0; while(SCANF ("%d%d", &n,&m)! =EOF) { for(intI=1; i<=n; i++) {scanf ("%d",&Num1[i]); Sum1[i]=sum1[i-1]+Num1[i]; Sub1[i]= -* -; } for(intI=1; i<=m; i++) {scanf ("%d",&Num2[i]); Sum2[i]=sum2[i-1]+Num2[i]; Sub2[i]= -* -; } scanf ("%i64d",&x); for(intI=1; i<=n; i++) for(intJ=i; j<=n; J + +) { intlen=j-i+1; Sub1[len]=min (sub1[len],sum1[j]-sum1[i-1]); } for(intI=1; i<=m; i++) for(intJ=i; j<=m; J + +) { intlen=j-i+1; Sub2[len]=min (sub2[len],sum2[j]-sum2[i-1]); } intres=0; for(intI=1; i<=n;i++) for(intj=1; j<=m;j++) if(LL) sub1[i]*sub2[j]<=x)//two sub multiply may be super int res=max (res,i*j); printf ("%d\n", RES); } return 0;}
Codeforces_c. Maximum Subrectangle