Make a 8*8 board such as the following: Cut the original checkerboard down a rectangular checkerboard and make the rest of the rectangle
The rest of the section continues to be so cut, so after cutting (n-1) times, together with the last remaining rectangular chessboard together with the N-Block rectangular chessboard.
(Each split can only be performed along the side of the checkerboard lattice)
Each lattice on the original board has a score, and the total score of a rectangular checkerboard is the sum of the scores of the squares it contains.
Now it is necessary to cut the chessboard into N rectangular chessboard according to the rules above, and to minimize the average variance of the total score of each rectangular checkerboard.
Mean variance
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvcgfuzg9yyv9tywrhcme=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/southeast, the average
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvcgfuzg9yyv9tywrhcme=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma== /dissolve/70/gravity/southeast ">. Xi is the total score of the block I rectangular checkerboard.
Please program on the given Checkerboard and N. Find the minimum value of O '.
#include <iostream> #include <cstring> #include <cmath> #include <iomanip> #include <fstream >using namespace Std;const int MAX = 1 << 30;int chessboard[9][9];int sums[9][9][9][9];d ouble dp[20][9][9][9][9] ; int N;int Main () {double totals = 0.0; Double avg = 0.0; memset (chessboard, 0, sizeof (chessboard)); memset (sums, 0, sizeof (sums)); FStream fin ("test.txt"); Cin >> N; for (int i = 1, i <= 8; ++i) {for (int j = 1; J <= 8; ++j) {cin >> chessboard[i][j]; SUMS[I][J][I][J] = Chessboard[i][j]; Totals + = Chessboard[i][j]; CHESSBOARD[I][J] + = Chessboard[i-1][j] + chessboard[i][j-1]-chessboard[i-1][j-1]; }} avg = totals/(N * 1.0); for (int x1 = 1; X1 <= 8, ++x1) {for (int y1 = 1, y1 <= 8; ++y1) {for (int x2 = x1; x2 <= 8; ++X2) {for (int y2 = y1; y2 <= 8; ++y2) { Sums[x1][y1][x2][y2] = Chessboard[x2][y2]-chessboard[x1-1][y2]-CHESSB Oard[x2][y1-1] + chessboard[x1-1][y1-1]; Dp[0][x1][y1][x2][y2] = sums[x1][y1][x2][y2] * Sums[x1][y1][x2][y2]; }}}} for (int k = 1, k <= N-1; ++k) {for (int x1 = 1; x1 <= 8; ++x1) { for (int y1 = 1; Y1 <= 8, ++y1) {for (int x2 = x1, x2 <= 8; ++x2) {for (int y 2 = y1; Y2 <= 8; ++y2) {Dp[k][x1][y1][x2][y2] = MAX; for (int mid = x1; mid < X2; ++mid) {Dp[k][x1][y1][x2][y2] = min (Dp[k][x1][y1][x2][y2], Dp[0][x1][y1][mid][y2] + dp[k-1][mid + 1][y1][x2][y2]); Dp[k][x1][y1][x2][y2] = min (Dp[k][x1][y1][x2][y2], dp[k-1][X1][y1][mid][y2] + dp[0][mid + 1][y1][x2][y2]); } for (int mid = Y1; mid < y2; ++mid) {Dp[k][x1][y1][x2][y2] = min ( Dp[k][x1][y1][x2][y2], Dp[0][x1][y1][x2][mid] + dp[k-1][x1][mid + 1][x2][y2]); Dp[k][x1][y1][x2][y2] = min (Dp[k][x1][y1][x2][y2], dp[k-1][x1][ Y1][x2][mid] + dp[0][x1][mid + 1][x2][y2]); }}}}} double ans = dp[n-1][1][1][8][8]/(N * 1.0)-A VG * AVG; cout << setprecision (3) << fixed << sqrt (ans) << Endl; return 0;}
Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.
Dynamic planning of vegetable Board