【BZOJ】1048: [HAOI2007]分割矩阵
http://www.lydsy.com/JudgeOnline/problem.php?id=1048
题意:给出一个a×b(a,b<=10)的矩阵,带一个<=100的权值,现在要切割n-1次变成n个矩形(n<=10),求
$$\sqrt{\frac{1}{n}\sum_{i=1}^{n}(sum[i]-\mu)}, \mu = \frac{\sum_{i=1}^{n} sum[i]}{n}, sum[i]表示矩阵的和$$
的最小值
#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; static 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 now=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=min(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, kk)+dfs(x1, i+1, x2, y2, k-kk));
return now;
} int main() {
init();
double ans=(double)dfs(1, 1, A, B, n-1)-(double)sqr(sum[A][B])/(double)n;
ans=sqrt((double)1/n)*sqrt(ans);
printf("%.2f\n", ans+1e-6);
return 0;
}
注意到数据很小....推一下公式就爆搜吧...
【BZOJ】1048: [HAOI2007]分割矩阵的更多相关文章
- BZOJ 1048 [HAOI2007]分割矩阵
1048: [HAOI2007]分割矩阵 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 623 Solved: 449[Submit][Status ...
- [BZOJ 1048] [HAOI2007] 分割矩阵 【记忆化搜索】
题目链接:BZOJ - 1048 题目分析 感觉这种分割矩阵之类的题目很多都是这样子的. 方差中用到的平均数是可以直接算出来的,然后记忆化搜索 Solve(x, xx, y, yy, k) 表示横坐标 ...
- 1048: [HAOI2007]分割矩阵 - BZOJ
Description 将一个a*b的数字矩阵进行如下分割:将原矩阵沿某一条直线分割成两个矩阵,再将生成的两个矩阵继续如此分割(当然也可以只分割其中的一个),这样分割了(n-1)次后,原矩阵被分割成了 ...
- 1048: [HAOI2007]分割矩阵
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1184 Solved: 863[Submit][Status][Discuss] Descripti ...
- bzoj千题计划186:bzoj1048: [HAOI2007]分割矩阵
http://www.lydsy.com/JudgeOnline/problem.php?id=1048 #include<cmath> #include<cstdio> #i ...
- 【BZOJ1048】 [HAOI2007]分割矩阵
[BZOJ1048][HAOI2007]分割矩阵 题面 bzoj 洛谷 题解 \(dp[a][b][c][d][num]\)表示将矩形\((a,b,c,d)\)分成\(num\)个的最小方差,然后转移 ...
- 洛谷P2217 [HAOI2007]分割矩阵
P2217 [HAOI2007]分割矩阵 题目描述 将一个a*b的数字矩阵进行如下分割:将原矩阵沿某一条直线分割成两个矩阵,再将生成的两个矩阵继续如此分割(当然也可以只分割其中的一个),这样分割了(n ...
- [HAOI2007]分割矩阵
题目描述 将一个a*b的数字矩阵进行如下分割:将原矩阵沿某一条直线分割成两个矩阵,再将生成的两个矩阵继续如此分割(当然也可以只分割其中的一个),这样分割了(n-1)次后,原矩阵被分割成了n个矩阵.(每 ...
- BZOJ1048:[HAOI2007]分割矩阵(记忆化搜索DP)
Description 将一个a*b的数字矩阵进行如下分割:将原矩阵沿某一条直线分割成两个矩阵,再将生成的两个矩阵继续如此分割(当然也可以只分割其中的一个), 这样分割了(n-1)次后,原矩阵被分割成 ...
随机推荐
- 【Django】如何按天 小时等查询统计?
代码: from django.db import connection from django.db.models import Sum,Count #alarm_sum_group_items = ...
- 【SpringMVC】SpringMVC系列1之HelloWorld
SpringMVC之HelloWorld 概述 SpringMVC 是基于 MVC 设计理念的优秀Web 框架,是目前最主流的 MVC 框架之一.Spring3.0 后全面超越 Struts2,成为最 ...
- 【leetcode】Subsets II
Subsets II Given a collection of integers that might contain duplicates, S, return all possible subs ...
- 【转】Oracle数据库中Sequence的用法
在Oracle数据库中,sequence等同于序列号,每次取的时候sequence会自动增加,一般会作用于需要按序列号排序的地方. 1.Create Sequence (注释:你需要有CREATE S ...
- Selenium测试Ajax程序(转)
上周末参加了Qclub的百度技术沙龙,听了百度的孙景卫讲了Web自动化测试,讲的非常好,然后在小组讨论时又有幸座在了一起.我们讨论的一个内容,就是Ajax应用程序比原来的非Ajax程序更不易测试,这里 ...
- 在SQLServer处理中的一些问题及解决方法 NEWSEQUENTIALID()
一.DBLINK性能问题select * from dbsource.dbname.dbo.table where guid in (select guid from tablechangelog w ...
- ini 文件操作记要(1): 使用 TIniFile
ini 文件操作记要(1): 使用 TIniFile unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Class ...
- Java for LeetCode 169 Majority Element
Given an array of size n, find the majority element. The majority element is the element that appear ...
- 9.装饰者模式(Decorator Pattern)
using System; namespace ConsoleApplication7 { class Program { static void Main(string[] args) { // 我 ...
- SQL的IN, SOME,ANY,IN
表dbo.Student有12条数据 name 123123123123123123123123123123123123大雄1阿华浩然菊花大姐123123 1.some,any用法一样(不知道有没有其 ...