#include #include #include #include using namespace std; const int oo=0x3f3f3f3f; int n,a[20][20],s[20][20],vis[20][20][20][20][20]; int f[20][20][20][20][20],tot; int dp(int R1,int C1,int R2,int C2,int tot) { int &res=f[R1][C1][R2][C2][tot]; if(vis[R1][C1][R2][C2][tot]) return res; vis[R1][C1][R2][C2][tot]=1; if(tot>(R2-R1+1)*(C2-C1+1)) return res=oo; if(tot==1) { double v=s[R2][C2]-s[R2][C1-1]-s[R1-1][C2]+s[R1-1][C1-1]; return res=v*v; } res=oo; for(int R=R1;R