dp/Memory Search
Violent enumeration partitioning scheme? ...... It's about a number of levels? It's about 20! solution = =?
But we see a, B, n range are very small ... So the number of different states is only $10^5$ level, can be memory search solution
Compare water to a problem ...
1 /**************************************************************2 problem:10483 User:tunix4 language:c++5 result:accepted6 time:132 Ms7 memory:2544 KB8 ****************************************************************/9 Ten //Bzoj 1048 One#include <cmath> A#include <vector> -#include <cstdio> -#include <cstring> the#include <cstdlib> -#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) + #defineF (i,j,n) for (int i=j;i<=n;++i) - #defineD (i,j,n) for (int i=j;i>=n;--i) + #definePB Push_back A using namespacestd; atInlineintGetint () { - intv=0, sign=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') sign=-1; Ch=GetChar ();} - while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} - returnv*Sign ; - } in Const intn=1e5+Ten, inf=~0u>>2; -typedefLong LongLL; totypedefDoubleLF; + /******************tamplate*********************/ - intA,b,n; the *LF f[ One][ One][ One][ One][ One],ave,v[ One][ One],s[ One][ One]; $LF Dfs (intX1,intY1,intX2,intY2,intN) {Panax NotoginsengLF &now=f[x1][y1][x2][y2][n],ans=Inf,val; - if(now!=-1.0)returnNow ; the if(n==1){ +Val=s[x2][y2]-s[x1-1][y2]-s[x2][y1-1]+s[x1-1][y1-1]; Anow= (Val-ave) * (val-Ave); the returnNow ; + } -F (i,x1,x2-1) F (k,1, N-1) $Ans=min (Ans,dfs (x1,y1,i,y2,k) +dfs (i+1, y1,x2,y2,n-k)); $F (j,y1,y2-1) F (k,1, N-1) -Ans=min (Ans,dfs (x1,y1,x2,j,k) +dfs (x1,j+1, x2,y2,n-k)); - returnnow=ans; the } - intMain () {Wuyi #ifndef Online_judge theFreopen ("1048.in","R", stdin); -Freopen ("1048.out","W", stdout); Wu #endif -A=getint (); B=getint (); n=getint (); AboutF (I,1, a) F (J,1, B) { $v[i][j]=getint (); -s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+V[i][j]; - } -ave=s[a][b]/N; AF (x1,0, a) F (Y1,0, b) F (x2,0, a) F (Y2,0, b) F (k,0, N) +f[x1][y1][x2][y2][k]=-1.0; theLF Ans=dfs (1,1, a,b,n); -ANS=SQRT (ans/n); $printf"%.2lf\n", ans); the return 0; the}
View Code 1048: [HAOI2007] Split matrix time limit:10 Sec Memory limit:162 MB
submit:576 solved:414
[Submit] [Status] [Discuss] Description
A a*b digital matrix is segmented as follows: The original matrix is divided into two matrices along a line, and then the resulting two matrices continue to be so segmented (or, of course, only one of them), so that the original matrix is divided into n matrices after splitting (n-1). (Each partition can only follow the gap between the numbers) there is a score in each position of the original matrix, and the total score of a matrix is the sum of the points in each position contained in it. Now we need to divide the matrix into n matrices according to the above rules, and minimize the mean variance of the total score of each matrix. Please program the given matrix and N to find the minimum value of the mean variance.
Input
The first behavior is a 3 integer that represents the value of A,b,n (1<a,b<=10,1<n<=10).
The second line to line n+1 each behavior b a nonnegative integer less than 100, representing the score at the corresponding position in the matrix. Each row is separated by a space between two adjacent numbers.
Output
Only one number, which is the minimum value of the mean variance (rounded to 2 digits after the decimal point)
Sample INPUT5 4 4
2 3 4 6
5 7 5 1
10 4 0 5
2 0 2 3
4 1 1 1Sample output0.50hintsource [Submit] [Status] [Discuss]
"Bzoj" "1048" "HAOI2007" Partition matrix