WA #3 #4两个点,与实际答案都只差大概0.01
查看原帖
WA #3 #4两个点,与实际答案都只差大概0.01
86973
花园Serena楼主2020/11/10 10:25

RT,是写错了还是爆精度了 代码如下

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define R register int
const int MAXN = 20;
double f[MAXN][MAXN][MAXN][MAXN][MAXN];
int s[MAXN][MAXN], a[MAXN][MAXN];
signed main() {
    int n; scanf("%lld", &n);
    for(R i = 1; i <= 8; i ++) 
        for(R j = 1; j <= 8; j ++)
            scanf("%lld", &a[i][j]);
    for(R i = 1; i <= 8; i ++)
        for(R j = 1; j <= 8; j ++)
            s[i][j] = a[i][j] + s[i][j - 1] + s[i - 1][j] - s[i - 1][j - 1];
    for(R i = 1; i <= 8; i ++)
        for(R j = 1; j <= 8; j ++)
            for(R l = i; l <= 8; l ++)
                for(R r = j; r <= 8; r ++) {
                    f[i][j][l][r][0] = s[l][r] - s[i - 1][r] - s[l][j - 1] + s[i - 1][j - 1] - s[8][8] / n;
                    f[i][j][l][r][0] *=f[i][j][l][r][0]; f[i][j][l][r][0] /= n;
                }
    for(R x = 1; x < n; x ++) 
        for(R i = 1; i <= 8; i ++)
            for(R j = 1; j <= 8; j ++)
                for(R l = 1; l <= 8; l ++)
                    for(R r = 1; r <= 8; r ++) {
                        double Min = 0x7fffffff;
                        for(R t = j; t < r; t++) {
                            Min = min(Min, f[i][j][l][t][x - 1] + f[i][t + 1][l][r][0]);
                            Min = min(Min, f[i][j][l][t][0] + f[i][t + 1][l][r][x - 1]);
                        }
                        for(R t = i; t < l; t ++) {
                            Min = min(Min, f[t + 1][j][l][r][0] + f[i][j][t][r][x - 1]);
                            Min = min(Min, f[t + 1][j][l][r][x - 1] + f[i][j][t][r][0]);
                        }
                        f[i][j][l][r][x] = Min;
                    }
    printf("%.3lf\n", sqrt(f[1][1][8][8][n - 1]));
    return 0;
}
2020/11/10 10:25
加载中...