http://poj.org/problem?id=1191

题意:中文题。

题解:

1.关于切割的模拟,用递归 有这样的递归方程(dp方程):f(n,棋盘)=f(n-1,待割的棋盘)+f(1,割下的棋盘)

2.考虑如何计算方差,根据以下方差公式

我们只需算∑X 2的最小值//然后将它乘以n,减去总和的平方,除以n^2,再整体开根号就行了,化简一下的结果

3.关于棋盘的表示,我们用左上角坐标与右下角坐标,常规表示

4.关于计算优化,用sum二维前缀和。并且进行记忆化递归。

技巧:1&引用 化简代码 2 二维前缀和的预处理

坑:我在poj上搜找这题,搜chess,rectangle,cut死活找不到,组后发现是到noi的中文题qrz。。。

  +1,-1 要注意

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <math.h>
#include <string.h>
#include <string>
#include <map>
#include<stack>
#include<set>
#include<string.h>
#include<iomanip>
#define pb push_back
#define _for(i, a, b) for (int i = (a); i<(b); ++i)
#define _rep(i, a, b) for (int i = (a); i <= (b); ++i) using namespace std;
const int N =+ ;
//double num[N], price[N], ave[N];
int s[N][N];
int sum[N][N];
int res[][N][N][N][N];
int calSum(int x1, int y1, int x2, int y2) {
return sum[x2][y2] - sum[x2][y1-] - sum[x1-][y2] + sum[x1-][y1-];
}
int f(int n, int x1, int y1, int x2, int y2) {
int t, a, b, c, e, mn = 1e7;
int& ans = res[n][x1][y1][x2][y2];
if (ans != -) return ans;
if (n == ) {
t = calSum(x1, y1, x2, y2);
ans = t*t;
return ans;
}
for (a = x1; a < x2; a++) {
c = calSum(a + , y1, x2, y2);
e = calSum(x1, y1, a, y2);
t = min(c*c + f(n - , x1, y1, a, y2), e*e + f(n-,a + , y1, x2, y2));
if (mn > t)mn = t;
}
for (b = y1; b < y2; b++) {
c = calSum(x1, b+, x2, y2);
e = calSum(x1, y1, x2, b);
t = min(c*c + f(n-,x1, y1, x2, b), e*e + f(n-,x1, b + , x2, y2));
if (mn > t)mn = t;
}
ans = mn;
return ans;
}
int main() {
memset(res, -, sizeof(res));
int n;
cin >> n; _for(i,,)
for(int j=,rowsum=;j<;j++) {
cin >> s[i][j];
rowsum += s[i][j];
sum[i][j] += sum[i - ][j] + rowsum;
} double result = n*f(n, , , , ) - sum[][] * sum[][];
cout << setiosflags(ios::fixed) << setprecision() << sqrt(result / (n*n)) << endl; system("pause");
}

POJ - 1191 棋盘分割 记忆递归 搜索dp+数学的更多相关文章

  1. HDU 2517 / POJ 1191 棋盘分割 区间DP / 记忆化搜索

    题目链接: 黑书 P116 HDU 2157 棋盘分割 POJ 1191 棋盘分割 分析:  枚举所有可能的切割方法. 但如果用递归的方法要加上记忆搜索, 不能会超时... 代码: #include& ...

  2. POJ 1191 棋盘分割 【DFS记忆化搜索经典】

    题目传送门:http://poj.org/problem?id=1191 棋盘分割 Time Limit: 1000MS   Memory Limit: 10000K Total Submission ...

  3. POJ 1191 棋盘分割(DP)

    题目链接 大体思路看,黑书...其他就是注意搞一个in数组,这样记忆化搜索,貌似比较快. #include <cstdio> #include <cstring> #inclu ...

  4. poj 1191 棋盘分割 动态规划

    棋盘分割 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11457   Accepted: 4032 Description ...

  5. POJ 1191 棋盘分割

    棋盘分割 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11213 Accepted: 3951 Description 将一个 ...

  6. POJ 1191棋盘分割问题

    棋盘分割问题 题目大意,将一个棋盘分割成k-1个矩形,每个矩形都对应一个权值,让所有的权值最小求分法 很像区间DP,但是也不能说就是 我们只要想好了一个怎么变成两个,剩下的就好了,但是怎么变,就是变化 ...

  7. poj 1191 棋盘分割(dp + 记忆化搜索)

    题目:http://poj.org/problem?id=1191 黑书116页的例题 将方差公式化简之后就是 每一块和的平方 相加/n , 减去平均值的平方. 可以看出来 方差只与 每一块的和的平方 ...

  8. POJ 1191 棋盘分割 (区间DP,记忆化搜索)

    题面 思路:分析公式,我们可以发现平均值那一项和我们怎么分的具体方案无关,影响答案的是每个矩阵的矩阵和的平方,由于数据很小,我们可以预处理出每个矩阵的和的平方,执行状态转移. 设dp[l1][r1][ ...

  9. (中等) POJ 1191 棋盘分割,DP。

    Description 将一个8*8的棋盘进行如下分割:将原棋盘割下一块矩形棋盘并使剩下部分也是矩形,再将剩下的部分继续如此分割,这样割了(n-1)次后,连同最后剩下的矩形棋盘共有n块矩形棋盘.(每次 ...

随机推荐

  1. AngularJS------报错"The selector "app-user-item" did not match any elements"

    原因:新建的组件没有在任何界面使用到 解决方法:在界面使用该组件

  2. PHP+Oracle Instant Client

    <?php <b>●Oracleとの接続テスト</b> <hr> <?php // Oracleとの接続 $conn = OCILogon(" ...

  3. Mybatis -- 批量更新 -- updateBatch

    mysql数据库配置: 数据库连接必须配置:&allowMultiQueries=true并且‘&’ 用&替换 jdbc.url=jdbc:mysql://192.168.10 ...

  4. InsertSql

    declare @hobby table(hobbyID int,hName nvarchar(100));insert into @hobby(hobbyID,hName)Select 1,'爬山' ...

  5. Spring boot配置log4j输出日志

    1. pom.xml文件中配置parent,版本选定[1.2.5.RELEASE] 关于为什么要选这个版本:我尝试使用[1.4.1.RELEASE],但该版本库里没有[spring-boot-star ...

  6. Synchronizing Threads and GUI in Delphi application

    Synchronizing Threads and GUI   See More About delphi multithreading tthread class user interface de ...

  7. Kubernetes 简介

    一.Kubernetes 相关概念 1. Kubernetes 是一个开源的容器集群管理系统,主要用来自动化部署容器 .自动扩展与收缩容器规模 .提供容器间的负载均衡2. Node:Node(节点)也 ...

  8. osgExp只能将3dmax中的动画导出为路径动画osg::AnimationPath,而不能导出osgAnimation::Animation。osg播放骨骼动画应该使用FBX格式

    通过实际的模型测试,导出为.osg文本格式,搜索animation,只能搜索到AnimationPathCallback,而搜索不到osgAnimation相关类 在OSGExp1.5.0源代码中搜索 ...

  9. Ubuntu下安装MySQL及简单操作

    Ubuntu上安装MySQL非常简单只需要几条命令就可以完成. 1. sudo apt-get install mysql-server 2. apt-get isntall mysql-client ...

  10. lua中的字符串操作(模式匹配)

    (一). 模式匹配函数在string库中功能最强大的函数是:string.find(字符串查找)string.gsub(全局字符串替换)string.gfind(全局字符串查找)string.gmat ...