可惜没如果=_= 时光的河入海流

## 1048: [HAOI2007]分割矩阵

Time Limit: 10 Sec  Memory Limit: 162 MB
Submit: 1040  Solved: 751
[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

0.50

## Source

 1 #include "bits/stdc++.h"
2 using namespace std;
3 typedef long long LL;
4 const int MAX=15;
5 int n,m,t;
6 double f[MAX][MAX][MAX][MAX][MAX];
7 int s[MAX][MAX];
8 double ave;
10     int x=1,an=0;char c=getchar();
11     while (c<'0' || c>'9') {if (c=='-') x=-1;c=getchar();}
12     while (c>='0' && c<='9') {an=an*10+c-'0';c=getchar();}
13     return an*x;
14 }
15 inline double mn(double x,double y){return x<y?x:y;}
16 double dfs(int a,int b,int c,int d,int x){
17     if (f[a][b][c][d][x]!=-1) return f[a][b][c][d][x];
18     if (x==1){
19         double zt;
20         zt=(s[c][d]-s[a-1][d]-s[c][b-1]+s[a-1][b-1])*1.0;
21         return f[a][b][c][d][x]=(zt-ave)*(zt-ave);
22     }
23     int i,j;double tmp=100000000.0;
24     for (i=a;i<c;i++){
25         for (j=1;j<x;j++){
26             tmp=mn(tmp,dfs(a,b,i,d,j)+dfs(i+1,b,c,d,x-j));
27         }
28     }
29     for (i=b;i<d;i++){
30         for (j=1;j<x;j++){
31             tmp=mn(tmp,dfs(a,b,c,i,j)+dfs(a,i+1,c,d,x-j));
32         }
33     }
34     return f[a][b][c][d][x]=tmp;
35 }
36 int main(){
37     freopen ("matrix.in","r",stdin);
38     freopen ("matrix.out","w",stdout);
39     int i,j;
41     memset(s,0,sizeof(s));
42     for (int i1=0;i1<=n+1;i1++) for (int i2=0;i2<=m+1;i2++) for (int i3=0;i3<=n+1;i3++) for (int i4=0;i4<=m+1;i4++) for (int i5=1;i5<=t;i5++) f[i1][i2][i3][i4][i5]=-1;
43     for (i=1;i<=n;i++){
44         for (j=1;j<=m;j++){
52 }