# bzoj千题计划186：bzoj1048: [HAOI2007]分割矩阵

http://www.lydsy.com/JudgeOnline/problem.php?id=1048

#include<cmath>
#include<cstdio>
#include<algorithm>

using namespace std;

int sum[11][11];
int n,m,k;

double ans=1e9;

double average;

bool vis[11][11][11][11][11];
double dp[11][11][11][11][11];

double dfs(int xl,int yl,int xr,int yr,int tot)
{
if(vis[xl][yl][xr][yr][tot]) return dp[xl][yl][xr][yr][tot];
double &now=dp[xl][yl][xr][yr][tot];
vis[xl][yl][xr][yr][tot]=true;
if(tot==1)
{
int tmp=sum[xr][yr]-sum[xl-1][yr]-sum[xr][yl-1]+sum[xl-1][yl-1];
now=(tmp-average)*(tmp-average);
return now;
}
now=2e9;
for(int i=xl;i<xr;++i)
for(int j=1;j<tot;++j)
now=min(now,dfs(xl,yl,i,yr,j)+dfs(i+1,yl,xr,yr,tot-j));
for(int i=yl;i<yr;++i)
for(int j=1;j<tot;++j)
now=min(now,dfs(xl,yl,xr,i,j)+dfs(xl,i+1,xr,yr,tot-j));
return now;
}

int main()
{
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;++i)
for(int j=1;j<=m;++j)
{
scanf("%d",&sum[i][j]);
sum[i][j]+=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
}
average=1.0*sum[n][m]/(k);
dfs(1,1,n,m,k);
printf("%.2lf",sqrt(dp[1][1][n][m][k]/k));
}

## 1048: [HAOI2007]分割矩阵

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 1118  Solved: 808
[Submit][Status][Discuss]

## Description

将一个a*b的数字矩阵进行如下分割：将原矩阵沿某一条直线分割成两个矩阵，再将生成的两个矩阵继续如此

5 4 4
2 3 4 6
5 7 5 1
10 4 0 5
2 0 2 3
4 1 1 1

## Sample Output

0.50
posted @ 2018-01-03 10:15  TRTTG  阅读(242)  评论(0编辑  收藏  举报