Greed, number of rectangles.
You can first record the number of rectangles (x,y) to the left, where you can apply a DP method
Then O (n^3) loop, it's not clear, look at the code.
/******************************************************************************* # Author:neo Fung # Email:neosfung @gmail. com # last modified:2012-02-29 20:24 # filename:zoj2067 White Rectangles.cpp # Description: *************** /#ifdef _msc_ver #define DEBUG #define _crt_secure_ No_deprecate #endif #include <fstream> #include <stdio.h> #include <iostream> #include <string.h&
Gt #include <string> #include <limits.h> #include <algorithm> #include <math.h> #include <
numeric> #include <functional> #include <ctype.h> #define MAX, using namespace std;
Char Board[max][max];
int Sum[max][max]; int main (void) {#ifdef DEBUG freopen (".
/stdin.txt "," R ", stdin); Freopen ("..
/stdout.txt "," w ", stdout);
#endif int n;
while (~SCANF ("%d", &n)) {memset (sum,0,sizeof (sum));
memset (board, ' # ', sizeof (board));
GetChar (); for (int i=1;I<=n;++i) gets (board[i]+1);
int ans=0;
for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) if (board[i][j]== '. ')
{if (board[i][j-1]!= '. ')
Sum[i][j]=1;
else sum[i][j]=sum[i][j-1]+1;
for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) {int len=int_max;
for (int k=i;k<=n && sum[k][j];++k) {len=min (len,sum[k][j]);
Ans+=len;
} printf ("%d\n", ans);
return 0;
}