1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| const int N = 8; const int maxn = 15 + 2;
int f[maxn][N + 2][N + 2][N + 2][N + 2]; int A[N + 2][N + 2]; int n; int S[N + 2][N + 2]; double tot = 0; const int inf = 0x3f3f3f3f;
void init() { Set(f, inf); Set(S, 0);
_rep(i, 1, N) _rep(j, 1, N) { S[i][j] = S[i-1][j] + S[i][j-1] - S[i-1][j-1] + A[i][j]; }
_rep(x1, 1, N) _rep(y1, 1, N) { _rep(x2, x1, N) _rep(y2, y1, N) { int t = S[x2][y2] - S[x2][y1-1] - S[x1-1][y2] + S[x1-1][y1-1]; f[0][x1][y1][x2][y2] = t * t; } } }
void dp(int k, int x1, int y1, int x2, int y2) { int& ans = f[k][x1][y1][x2][y2]; ans = inf;
_for(a, x1, x2) { ans = min(ans, f[k-1][x1][y1][a][y2] + f[0][a+1][y1][x2][y2]); ans = min(ans, f[k-1][a+1][y1][x2][y2] + f[0][x1][y1][a][y2]); }
_for(b, y1, y2) { ans = min(ans, f[k-1][x1][y1][x2][b] + f[0][x1][b+1][x2][y2]); ans = min(ans, f[k-1][x1][b+1][x2][y2] + f[0][x1][y1][x2][b]); } }
int main() { freopen("input.txt", "r", stdin); scanf("%d", &n);
_rep(i, 1, N) _rep(j, 1, N) { scanf("%d", &A[i][j]); tot += A[i][j]; }
init(); _rep(k, 1, n - 1) _rep(x1, 1, N) _rep(y1, 1, N) { _rep(x2, x1, N) _rep(y2, y1, N) { dp(k, x1, y1, x2, y2); } }
double avr = (double)(tot / n); //debug(tot); double ans = sqrt(1.0 * f[n - 1][1][1][N][N] / n - (avr * avr)); printf("%.3f\n", ans); }
|