POJ1991 NOI1999棋盘分割
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 15581 | Accepted: 5534 |
Description

原棋盘上每一格有一个分值,一块矩形棋盘的总分为其所含各格分值之和。现在需要把棋盘按上述规则分割成n块矩形棋盘,并使各矩形棋盘总分的均方差最小。
均方差
请编程对给出的棋盘及n,求出O'的最小值。
Input
第2行至第9行每行为8个小于100的非负整数,表示棋盘上相应格子的分值。每行相邻两数之间用一个空格分隔。
Output
Sample Input
3
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
Sample Output
1.633
Source
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define dist(x1, y1, x2, y2) (g[(x2)][(y2)] - g[((x1) - 1)][(y2)] - g[(x2)][((y1) - 1)] + g[((x1) - 1)][((y1) - 1)]) inline void read(long long &x)
{
x = ;char ch = getchar(), c = ch;
while(ch < '' || ch > '')c = ch, ch = getchar();
while(ch <= '' && ch >= '')x = x * + ch - '', ch = getchar();
if(c == '-')x = -x;
} const long long MAXN = + ; long long n, g[][], dp[MAXN][][][][], sum; int main()
{
read(n);
for(register long long i = ;i <= ;++ i)
for(register long long j = ;j <= ;++ j)
{
read(g[i][j]);
sum += g[i][j];
g[i][j] = g[i - ][j] + g[i][j - ] - g[i - ][j - ] + g[i][j];
}
memset(dp, 0x3f, sizeof(dp));
//dp[i][x1][y1][x2][y2]表示把(x1,y1)(x2,y2)矩形切割成i块的最小平方和
for(register long long i = ;i <= n;++ i)
for(register long long x1 = ;x1 <= ;++ x1)
for(register long long y1 = ;y1 <= ;++ y1)
for(register long long x2 = ;x2 <= ;++ x2)
for(register long long y2 = ;y2 <= ;++ y2)
{
if(i == )
{
dp[i][x1][y1][x2][y2] = dist(x1, y1, x2, y2)*dist(x1, y1, x2, y2);
continue;
}
for(register long long a = x1;a < x2;++ a)
{
dp[i][x1][y1][x2][y2] = min(dp[i][x1][y1][x2][y2], dp[i - ][x1][y1][a][y2] + dist(a + , y1, x2, y2)*dist(a + , y1, x2, y2));
dp[i][x1][y1][x2][y2] = min(dp[i][x1][y1][x2][y2], dp[i - ][a + ][y1][x2][y2] + dist(x1, y1, a, y2)*dist(x1, y1, a, y2));
}
for(register long long a = y1;a < y2;++ a)
{
dp[i][x1][y1][x2][y2] = min(dp[i][x1][y1][x2][y2], dp[i - ][x1][y1][x2][a] + dist(x1, a + , x2, y2)*dist(x1, a + , x2, y2));
dp[i][x1][y1][x2][y2] = min(dp[i][x1][y1][x2][y2], dp[i - ][x1][a + ][x2][y2] + dist(x1, y1, x2, a)*dist(x1, y1, x2, a));
}
}
printf("%.3lf", (double)sqrt(((double)dp[n][][][][]*1.0/n) - ((double)sum*1.0/n) * ((double)sum*1.0/n)));
return ;
}
POJ1991
POJ1991 NOI1999棋盘分割的更多相关文章
- [NOI1999] 棋盘分割
COGS 100. [NOI1999] 棋盘分割 http://www.cogs.pro/cogs/problem/problem.php?pid=100 ★★ 输入文件:division.in ...
- [NOI1999] 棋盘分割(推式子+dp)
http://poj.org/problem?id=1191 棋盘分割 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 156 ...
- 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 ...
随机推荐
- elasticsearch复合查询
查询最近一小时内data.@level字段为Error的日志并按date倒序排列,输出最近10条,只输出[date,message]两个字段 GET events*/_search { &qu ...
- PAT甲级——A1002 A+B for Polynomials
This time, you are supposed to find A+B where A and B are two polynomials. Input Specification: Each ...
- springmvc-@RequestBody无法映射首字母大写的属性
@RequestBody可以将前台传入的json格式数据自动映射成对象,当如果属性的首字母大写,则会出现不能映射的情况,如: private String ICCID;会出现映射失败的情况 解决办法: ...
- line-height影响排版
父级div设置了line-height值,子级div会继承line-height.如果不想子级元素继承,给子级元素设置line-height:normal.
- FPFH+ICP点云配准
A, UniformSampling降噪 B, ISS计算关键点, FPFH特征 在FeatureCloud::setInputCloud中读入点云,并调用processInput进行处理: proc ...
- mongoDB可视化工具RoBo 3T的安装和使用
第一步下载RoBo3T https://robomongo.org/download 第二步安装 双击安装包安装,修改安装路径,不停下一步,点击安装. 一路next,最后到了这个页面直接点击finis ...
- Sublime text3 代码格式化插件vue
同事用的windows的sublime轻量级容易上手.我们现在强制eslint规范.我们就需要安装这个格式化代码的插件"html-css-js-prettify" 使用 Subli ...
- js匿名函数与闭包作用
http://www.jb51.net/article/79238.htm 1 闭包允许内层函数引用父函数中的变量,但是该变量是最终值 当mouseover事件调用监听函数时,首先在匿名函数( fun ...
- jeecms各种标签类(大部分,并没有包含一些其他的如text_cut html_cut之类)
软件包 comjeecms.cms.action.directive 类摘要 ChannelDirective 栏目对象标签 ChannelListDirective 栏目列表标签 ChannelPa ...
- 线段树区间更新+区间求和模板(数组实现)洛谷p3372,p3373
模板题目1:https://www.luogu.org/problemnew/show/P3372 懒惰标记讲解:https://www.cnblogs.com/wushengyang/p/11194 ...