[NOI1999] 棋盘分割
COGS 100. [NOI1999] 棋盘分割
http://www.cogs.pro/cogs/problem/problem.php?pid=100
★★ 输入文件:division.in 输出文件:division.out 简单对比
时间限制:1 s 内存限制:128 MB
【问题描述】
将一个8×8的棋盘进行如下分割:将原棋盘割下一块矩形棋盘并使剩下部分也是矩形,再将分割过的部分任选一块继续如此分割,这样割了n-1次后,连同最后剩下的矩形棋盘共有n块矩形棋盘。(每次切割都只能沿着棋盘格子的边进行)
,其中平均值
x i 为第 i 块矩形棋盘的分。
的最小值。第 2 行至第 9 行每行为 8 个小于 100 的非负整数,表示棋盘上相应格子的分值。每行相邻两数之间用一个空格分隔。
(四舍五入精确到小数点后三位)。1 1 1 1 1 1 1 3
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 0
1 1 1 1 1 1 0 3



#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define INF 1e9
using namespace std;
int n,a[][],dp[][][][][],s[][][][];
int add(int x1,int y1,int x2,int y2)
{
int tmp=;
for(int i=x1;i<=x2;i++)
for(int j=y1;j<=y2;j++)
tmp+=a[i][j];
return tmp;
}
int dfs(int k,int x1,int y1,int x2,int y2)
{
if(dp[k][x1][y1][x2][y2]!=INF) return dp[k][x1][y1][x2][y2];
if(x2>x1)
{
for(int i=x1;i<x2;i++)
{
int t1=dfs(k-,x1,y1,i,y2),t2=dfs(k-,i+,y1,x2,y2);
int t=min(t1+s[i+][y1][x2][y2],t2+s[x1][y1][i][y2]);
dp[k][x1][y1][x2][y2]=min(dp[k][x1][y1][x2][y2],t);
}
}
if(y2>y1)
{
for(int i=y1;i<y2;i++)
{
int t1=dfs(k-,x1,y1,x2,i),t2=dfs(k-,x1,i+,x2,y2);
int t=min(t1+s[x1][i+][x2][y2],t2+s[x1][y1][x2][i]);
dp[k][x1][y1][x2][y2]=min(dp[k][x1][y1][x2][y2],t);
}
}
return dp[k][x1][y1][x2][y2];
}
int main()
{
/*freopen("division.in","r",stdin);
freopen("division.out","w",stdout);*/
scanf("%d",&n);
for(int i=;i<=;i++)
for(int j=;j<=;j++)
scanf("%d",&a[i][j]);
for(int k=;k<=n;k++)
for(int x1=;x1<=;x1++)
for(int y1=;y1<=;y1++)
for(int x2=;x2<=;x2++)
for(int y2=;y2<=;y2++)
dp[k][x1][y1][x2][y2]=INF;
for(int x1=;x1<=;x1++)
for(int y1=;y1<=;y1++)
for(int x2=;x2<=;x2++)
for(int y2=;y2<=;y2++)
{
int tmp=add(x1,x2,y1,y2);
dp[][x1][x2][y1][y2]=s[x1][x2][y1][y2]=tmp*tmp;
}
int tmp=dfs(n,,,,);
int px=add(,,,);
double t=((double) (px) / n )*((double) (px) / n );
double r= (double) (tmp) / n;
printf("%.3lf",sqrt(r-t));
}
[NOI1999] 棋盘分割的更多相关文章
- [NOI1999] 棋盘分割(推式子+dp)
http://poj.org/problem?id=1191 棋盘分割 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 156 ...
- POJ1991 NOI1999棋盘分割
棋盘分割 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 15581 Accepted: 5534 Description ...
- POJ 1191 棋盘分割
棋盘分割 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11213 Accepted: 3951 Description 将一个 ...
- poj 1191 棋盘分割 动态规划
棋盘分割 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11457 Accepted: 4032 Description ...
- NOI 193棋盘分割.cpp
193:棋盘分割 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 65536kB 描述 将一个8*8的棋盘进行如下分割:将原棋盘割下一块矩形棋盘并使剩下部分也是矩形,再将剩下的部分 ...
- HDU 2517 / POJ 1191 棋盘分割 区间DP / 记忆化搜索
题目链接: 黑书 P116 HDU 2157 棋盘分割 POJ 1191 棋盘分割 分析: 枚举所有可能的切割方法. 但如果用递归的方法要加上记忆搜索, 不能会超时... 代码: #include& ...
- POJ 1191棋盘分割问题
棋盘分割问题 题目大意,将一个棋盘分割成k-1个矩形,每个矩形都对应一个权值,让所有的权值最小求分法 很像区间DP,但是也不能说就是 我们只要想好了一个怎么变成两个,剩下的就好了,但是怎么变,就是变化 ...
- 洛谷 P1436 棋盘分割 解题报告
P1436 棋盘分割 题目描述 将一个8*8的棋盘进行如下分割:将原棋盘割下一块矩形棋盘并使剩下部分也是矩形,再将剩下的两部分中的任意一块继续如此分割,这样割了(n-1)次后,连同最后剩下的矩形棋盘共 ...
- poj1191 棋盘分割【区间DP】【记忆化搜索】
棋盘分割 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16263 Accepted: 5812 Description ...
随机推荐
- svm小问题
1.没有报错但是结果是pedicttestlabel = [] accuracy = [] 举例:(前提是装了工具箱libsvm-3.21) data=[178,80;172,75;160,50;15 ...
- Robot Framework 教程 (5) - 连接Oracel数据库
Robot Framework 提供了多种Library.其中Database Library可用来连接操作数据库. 1.安装Database Library 打开Robot Framework官网, ...
- python 菜鸟入门
python 菜鸟博客: http://www.cnblogs.com/wupeiqi/articles/5433893.html http://www.cnblogs.com/linhaifeng/ ...
- HBase 架构与工作原理4 - 压缩、分裂与故障恢复
本文系转载,如有侵权,请联系我:likui0913@gmail.com Compacation HBase 在读写的过程中,难免会产生无效的数据以及过小的文件,比如:MemStore 在未达到指定大小 ...
- C语言版kafka消费者代码运行时异常kafka receive failed disconnected
https://github.com/edenhill/librdkafka/wiki/Broker-version-compatibility如果使用了broker版本是0.8的话, 在运行例程时需 ...
- 血液检测 & 创业骗局
血液检测 & 创业骗局 硅谷血液检测公司 Theranos http://www.sohu.com/a/236659372_100053377 https://www.jianshu.com/ ...
- MachineLearning Exercise 4 :Neural Networks Learning
nnCostFunction 消耗公式: a1 = [ones(m,) X]; z2 = a1*Theta1'; pre = sigmoid(a1*Theta1'); a2 = [ones(m,) p ...
- Oracle 事务实例(非理论)
begin begin savepoint p1; ---------============ 在这里写删改差语句(SELECT 不行)每句以分号结尾:如 delete ta ...
- mybatis plugin作为一款优秀的mybatis跳转插件
阅读目录: 1. 简介2. 下载mybatis plugin插件3. 安装mybatis plugin插件4. 启动并验证5.说明1. 简介 mybatis plugin作为一款优秀的mybatis跳 ...
- 学习Spring Boot:(九)统一异常处理
前言 开发的时候,每个controller的接口都需要进行捕捉异常的处理,以前有的是用切面做的,但是SpringMVC中就自带了@ControllerAdvice ,用来定义统一异常处理类,在 Spr ...