The mystery kidnapping case .Time limit:3000/1000ms (java/others) Memory limit:65535/65535kb (java/others)SubmitStatus
Winter horse was kidnapped by Fang Master!!!
One day, Chunch received an envelope with a 8x8 Board paper, a secret USB stick and a note. The note reads:
Winter horse in my hand, if you want to save winter horse, U disk has my detailed address, of course, if you can solve the password!
You can divide the chessboard into blocks of n , and each time you can cut a rectangle from a chessboard and let the rest of the section be rectangular, then divide the rest.
The original chessboard has a score for each lattice, and the total score of a rectangle is the sum of the scores of each lattice. You need to divide the chessboard into n blocks according to the above method , and find out the mean variance of the total score of each rectangle checkerboard. I don't mind telling you that the minimum value in all mean variance is the password of the U-disk, so please struggle!
Average formula:
x¯=∑nI=1xin
Mean Variance formula:
Σ=∑ni=1< Span id= "mathjax-span-319" class= "Mo" > (xi−x ¯) 2n−−−−−−−−−−−−√
------Master to stay
Chunch very anxious to find you, hope you can find this minimum value, rescued winter horse.
Input
First line an integer n , which represents the number of blocks after splitting. (1< n<15)
The second line to line Nineth, each row of eight non-negative integers less than four, indicating the score of the corresponding lattice on the board.
Output
A number that represents the minimum value to be calculated. (rounded to three digits after the decimal point)
Sample Input and output
Sample Input |
Sample Output |
31 1 1 1 1 1 1 31 1 1 1 1 1 1 11 1 1 1 1 1 1 11 1 1 1 1 1 1 11 1 1 1 1 1 1 11 1 1 1 1 1 1 11 1 1 1 1 1 1 01 0 3 |
1.633 |
Source2014 UESTC Training for Dynamic programmingProblem Solving Report..... The biggest pit point of this problem lies in the test instructions. (I had a tragic two-hour error, and found the problem read wrong ...) )Notice that you cut the rectangle once, there is one side can not cut again!!! that is, every time you cut, you can only choose one side to continue to cut (play drunk)A memory search, F (i,j,k) means that the rectangle with the upper corner number is I, the lower right corner of the number J is divided into the smallest (x-x_) ^2 value of the K block.the rest of the search is the (water problem)
1#include <iostream>2#include <algorithm>3#include <cstdio>4#include <cstring>5#include <cmath>6 using namespacestd;7 Const intMAXN =Ten;8 intSum[maxn][maxn],n;9 Doublef[ -][ -][ -],average=0.;Ten BOOLarrive[ -][ -][ -]; One AInlineintGETR (intx) - { - return(X-1)/8+1; the } - -InlineintGetcintx) - { + return(X-1) %8+1; - } + A atInlineintGetIDintXinty) - { - return(X-1)*8+y; - } - - in DoubleGetval (intLeftintRight ) - { to intSUMX =0 ; + intrst = Getr (left), red = GETR (right), CST = GETC (left), ced =getc (right); - for(inti = rst; I <= red; ++i) theSumx + = sum[i][ced]-sum[i][cst-1]; * return(Double) (sumx-average) * (SUMX-average); $ }Panax Notoginseng - DoubledpintLeftintRightintTimes ) the { + if(Arrive[left][right][times]) A returnF[left][right][times]; the Double&ans = F[left][right][times] =1e110; +Arrive[left][right][times] =true; - intrst = Getr (left), red = GETR (right), CST = GETC (left), ced =getc (right); $ intNumber = (Red-rst +1) * (CED-CST +1); $ if(Times >Number ) - returnans; - if(Times = =1)//cannot continue cutting the returnAns =Getval (left,right); - //vertical cut.Wuyi for(inti = CST +1; I <= ced; ++i) the { - intNewleft =GetID (rst,i); Wu intNewright = GetID (red,i-1); -ans = min (ans,getval (left,newright) +DP (newleft,right,times-1));//take the right and continue cutting . Aboutans = min (ans,getval (newleft,right) +DP (left,newright,times-1));//take the left and continue cutting . $ } - //cut sideways. - for(inti = rst; i < red; ++i) - { A for(intj =1; J <= times-1; ++j) + { the intNewleft = GetID (i+1, CST); - intNewright =GetID (i,ced); $ans = min (ans,getval (left,newright) +DP (newleft,right,times-1));//take the following and continue cutting . theans = min (ans,getval (newleft,right) +DP (left,newright,times-1));//take the top and keep cutting . the } the } the returnans; - } in the the About intMainintargcChar*argv[]) the { thememset (SUM,0,sizeof(sum)); thememset (Arrive,false,sizeof(arrive)); +scanf"%d",&n); - for(inti =1; I <=8; ++i) the for(intj =1; J <=8; ++j)Bayi { the inttemp; thescanf"%d",&temp); -SUM[I][J] = sum[i][j-1] +temp; -Average + = (Double) temp; the } theAverage/=N; theprintf"%.3f\n", SQRT (DP (1, -, N)/n)); the return 0; -}
UESTC_ Mysterious kidnapping case Cdoj 881