Test instructions: give you a 40x40 01 rectangle, and now give you a Q query (1,1000000), how many rectangles in a rectangle and 0.
Thinking of solving problems: Dp,n^4 pretreatment, mainly two state transfer equations
1) Dp[i][j][s] = Dp[i][j-1][s] + 1 (mp[i][j] = = 0)
2) Ans[lx][ly][i][j] + + ans[lx][ly][i-1][j] + ans[lx][ly][i][j-1]-ans[lx][ly][i-1][j-1]
Problem Solving Code:
1 //File name:372b.cpp2 //Author:darkdream3 //Created time:2015 March 29 Sunday 20:52 13 seconds4 5#include <vector>6#include <list>7#include <map>8#include <Set>9#include <deque>Ten#include <stack> One#include <bitset> A#include <algorithm> -#include <functional> -#include <numeric> the#include <utility> -#include <sstream> -#include <iostream> -#include <iomanip> +#include <cstdio> -#include <cmath> +#include <cstdlib> A#include <cstring> at#include <ctime> - #defineLL Long Long - #defineMAXN 45 - using namespacestd; - intN, M, q; - intDP[MAXN][MAXN][MAXN]; in intVAL[MAXN][MAXN]; - intANS[MAXN][MAXN][MAXN][MAXN]; to intMP[MAXN][MAXN]; + voidSolveintLxintly) - { theMemset (DP,0,sizeof(DP)); * for(inti = lx; I <= N;i + +) $ for(intj = ly; J <= M;j + +)Panax Notoginseng { - for(ints = i; s >= lx; S--) the { + if(Mp[s][j] = =0 ) A { theDp[i][j][s] = dp[i][j-1][s] +1; +ANS[LX][LY][I][J] + =Dp[i][j][s]; -}Else{ $ Break; $ } - } -ANS[LX][LY][I][J] + = ans[lx][ly][i-1][J] + ans[lx][ly][i][j-1]-ans[lx][ly][i-1][j-1] ; the } - }Wuyi intMain () { thescanf" %d%d%d",&n,&m,&q); - for(inti =1; I <= N;i + +) Wu { - for(intj =1; J <= M;j + +) About { $scanf"%1d",&mp[i][j]); - } - } - for(inti =1; I <= N;i + +) A for(intj =1; J <= M;j + +) + { the solve (i,j); - } $ intLx,ly,rx,ry; the while(q--) the { thescanf"%d %d%d%d",&lx,&ly,&rx,&ry); theprintf"%d\n", Ans[lx][ly][rx][ry]); - } in return 0; the}View Code
Codeforces 372B counting rectangles is fun