"Bzoj" 1048: [HAOI2007] Split matrix

Source: Internet
Author: User

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

Give a AXB (a,b<=10) matrix, with a <=100 weight, now to cut n-1 times into n rectangles (n<=10), ask

$$\sqrt{\frac{1}{n}\sum_{i=1}^{n} (SUM[I]-\MU)}, \mu = \frac{\sum_{i=1}^{n} sum[i]}{n}, Sum[i] represents the and $$ of the matrix

The minimum value

#include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream > #include <algorithm> #include <queue> #include <set> #include <map> #include <sstream >using namespace Std;typedef long long ll; #define PB Push_back#define Rep (i, n) for (int i=0; i< (n); ++i) #define For1 (i,a,n) for (int i= (a), i<= (n), ++i) #define FOR2 (i,a,n) for (int i= (a);i< (n), ++i) #define FOR3 (i,a,n) for (int i= (a); I >= (n); i) #define FOR4 (i,a,n) for (int i= (a);i> (n); i) #define CC (i,a) memset (i,a,sizeof (i)) #define READ (a) a=  Getint () #define PRINT (a) printf ("%d", a) #define DBG (x) cout << (#x) << "=" << (x) << Endl#define Error (x) (! ( x) puts ("error"): 0) #define RDM (x, i) for (int i=ihead[x]; i; i=e[i].next) inline int getint () {static int r, K; r=0,k=1; St Atic Char C; C=getchar (); for (; c< ' 0 ' | | C> ' 9 '; C=getchar ()) if (c== '-') k=-1; for (; c>= ' 0 ' &&c<= ' 9 '; C=getchar ()) r=r*10+c-' 0 '; return k*r; }const int n=11, Oo=~0u>>2;int w[n][n], f[n][n][n][n][n], A, B, N, Sum[n][n];void init () {CC (F,-1); Read (A); Read (B); read (n); For1 (I, 1, a) For1 (J, 1, b) read (w[i][j]); For1 (I, 1, a) For1 (J, 1, b) sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+ W[I][J];} int getsum (int x1, int y1, int x2, int y2) {return sum[x2][y2]-sum[x2][y1-1]-sum[x1-1][y2]+sum[x1-1][y1-1];} int sqr (int x) {return x*x;} int dfs (int x1, int y1, int x2, int y2, int k) {int &now=f[x1][y1][x2][y2][k];if (NOW!=-1) return now;if (k==0) return n OW=SQR (Getsum (x1, y1, x2, y2)); if (x1==x2 && y1==y2) return Now=oo;now=oo;--k;for2 (i, X1, x2) for1 (KK, 0, K) now=mi N (now, DFS (x1, y1, I, Y2, kk) +dfs (i+1, y1, x2, y2, k-kk)); For2 (i, Y1, y2) for1 (KK, 0, K) now=min (now, DFS (x1, y1, x2, I, K k) +dfs (x1, i+1, x2, y2, k-kk)); return now;} int main () {init ();d ouble ans= (Double) DFS (1, 1, A, B, n-1)-(double) sqr (Sum[a][b])/(double) n;ans=sqrt ((double) 1/n) * sqrt (ans);p rintf ("%.2f\n", ans+1e-6); return 0;}

  

Notice that the data is small .... Push the formula and pop the search ...

"Bzoj" 1048: [HAOI2007] Split matrix

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.