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 ...
随机推荐
- springboot与安全
概念: 安全 Spring Security是针对Spring项目的安全框架,也是Spring Boot底层安全模块默认的技术选型.他可以实现强大的web安全控制.对于安全控制,我们仅需引入sprin ...
- Cannot find module '@babel/plugin-proposal-class-properties'
cnpm install --save-dev @babel/plugin-proposal-class-properties
- Windows安全证书生成方法(开发者证书)
首先,查看本机安装的证书可在“运行”中输入:certmgr.msc 一.win8.8.1.win10系统,使用管理员powershell创建证书: (1)利用如下命令来创建证书并获取到其指纹 New- ...
- 设定计算属性setter
<!DOCTYPE html> <html lang="zh"> <head> <title></title> < ...
- js 面向对象类
类的声明 继承的几种方法 类的声明 第一种 function car(){ this.name = 'name'; } 第二种.es6中新添加的 class car(){ constructor(){ ...
- vue 可复用swiper以及scoped样式穿透(可以不受scoped的限制来修改样式)
参考: https://blog.csdn.net/dwb123456123456/article/details/82701740https://blog.csdn.net/u014027876/a ...
- 构建HBase二级索引
- GULP入门之API(二)
GULP的API gulp.src(globs[, options]) 输出(Emits)符合所提供的匹配模式(glob)或者匹配模式的数组(array of globs)的文件. 将返回一个 Vin ...
- sql 书写顺序
SELECT select_list [ INTO new_table ] FROM table_source [ WHERE search_condition ] [ GROUP BY group_ ...
- OSG能够在当前帧截图,也就是能转换视角后马上截图
#include <Windows.h> #include <osg/GraphicsContext> #include <osg/Group> #include ...