import java.io.*;
class Main{
static BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
static int N = 15, M = 9;
static double[][][][][] dp = new double[M][M][M][M][N];
static double[][] s = new double[M][M]; //矩阵前缀和
static double X, X2;
static int n;
static int INF = 0x3f3f3f3f;
public static void main(String[] args) throws Exception{
n = Integer.valueOf(read.readLine());
for(int i = 1; i <= 8; i++){
String[] ss = read.readLine().split(" +");
for(int j = 1; j <= 8; j++){
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + Integer.valueOf(ss[j - 1]);
}
}
X = s[8][8] / n;
X2 = X * X;
dfs(1, 1, 8, 8, n);
System.out.println(String.format("%.3f",Math.sqrt(dp[1][1][8][8][n])));
}
public static double dfs(int x1, int y1, int x2, int y2, int k){
double val = dp[x1][y1][x2][y2][k];
if(val > 0) return val;
if(k == 1) {
dp[x1][y1][x2][y2][k] = get(x1, y1, x2, y2);
return dp[x1][y1][x2][y2][k];
}
double min = INF;
//横切
for(int i = x1; i < x2; i++){
//上半部分
min = Math.min(min, dfs(x1, y1, i, y2, k - 1) + get(i + 1, y1, x2, y2));
//下半部分
min = Math.min(min, dfs(i + 1, y1, x2, y2, k - 1) + get(x1, y1, i, y2));
}
//纵切
for(int j = y1; j < y2; j++){
min = Math.min(min, dfs(x1, y1, x2, j, k - 1) + get(x1, j + 1, x2, y2));
min = Math.min(min, dfs(x1, j + 1, x2, y2, k - 1) + get(x1, y1, x2, j));
}
dp[x1][y1][x2][y2][k] = min;
return min;
}
public static double get(int x1 , int y1 , int x2 , int y2){
double sum = s[x2][y2] - s[x2][y1-1] - s[x1-1][y2] + s[x1-1][y1-1] ;
sum -= X ;
return sum * sum / n ;
}
}
请问为什么i还要加1不应该分割后都在同一个点吗
同学,您好,请问您知道咱们之前哪里学过记忆化搜索吗
你看看提高课有没有吧,我也记不清了
你好请问是用什么画图工具
windows自带的画图工具