1.链接地址:

http://bailian.openjudge.cn/practice/1191/

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

2.题目:

总时间限制:
1000ms
内存限制:
65536kB
描述
将一个8*8的棋盘进行如下分割:将原棋盘割下一块矩形棋盘并使剩下部分也是矩形,再将剩下的部分继续如此分割,这样割了(n-1)次后,连同最后剩下的矩形棋盘共有n块矩形棋盘。(每次切割都只能沿着棋盘格子的边进行)

原棋盘上每一格有一个分值,一块矩形棋盘的总分为其所含各格分值之和。现在需要把棋盘按上述规则分割成n块矩形棋盘,并使各矩形棋盘总分的均方差最小。
均方差,其中平均值,xi为第i块矩形棋盘的总分。
请编程对给出的棋盘及n,求出O'的最小值。
输入
第1行为一个整数n(1 < n < 15)。
第2行至第9行每行为8个小于100的非负整数,表示棋盘上相应格子的分值。每行相邻两数之间用一个空格分隔。
输出
仅一个数,为O'(四舍五入精确到小数点后三位)。
样例输入
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
样例输出
1.633
来源
Noi 99

3.思路:

确定公式的常量

深搜+剪枝

4.代码:

 #include <iostream>
#include <cstdio>
#include <cmath> #define NUM 8 using namespace std; double res_sigma; int n;
int arr[NUM][NUM]; double all_avg; double sigma; void dfs(int x1,int y1,int x2,int y2,int sum,int cut)
{
int k,i,j;
int temp_sum,temp_avg;
double temp; if(cut == )
{
temp = (sum - all_avg) * (sum - all_avg);
if(sigma + temp < res_sigma) {res_sigma = sigma + temp;}
return;
} temp_sum = ;
for(k = y1; k < y2; ++k)
{
for(j = x1; j <= x2; ++j) temp_sum += arr[k][j]; temp_avg = temp_sum;
temp = (all_avg - temp_avg) * (all_avg - temp_avg);
if(sigma + temp < res_sigma)
{
sigma += temp;
dfs(x1,k + ,x2,y2,sum - temp_sum,cut - );
sigma -= temp;
} temp_avg = sum - temp_sum;
temp = (all_avg - temp_avg) * (all_avg - temp_avg);
if(sigma + temp < res_sigma)
{
sigma += temp;
dfs(x1,y1,x2,k,temp_sum,cut - );
sigma -= temp;
} } temp_sum = ;
for(k = x1; k < x2; ++k)
{
for(i = y1; i <= y2; ++i) temp_sum += arr[i][k]; temp_avg = temp_sum;
temp = (all_avg - temp_avg) * (all_avg - temp_avg);
if(sigma + temp < res_sigma)
{
sigma += temp;
dfs(k + ,y1,x2,y2,sum - temp_sum,cut - );
sigma -= temp;
} temp_avg = sum - temp_sum;
temp = (temp_avg - all_avg) * (temp_avg - all_avg);
if(sigma + temp < res_sigma)
{
sigma += temp;
dfs(x1,y1,k,y2,temp_sum,cut - );
sigma -= temp;
} }
} int main()
{
//freopen("C://input.txt","r",stdin); cin >> n; int i,j; int sum = ;
for(i = ; i < NUM; ++i)
{
for(j = ; j < NUM; ++j)
{
cin >> arr[i][j];
sum += arr[i][j];
}
}
all_avg = sum * 1.0 / n; res_sigma = sum * sum * n; dfs(,,NUM - ,NUM - ,sum,n - ); cout.setf(ios::fixed);
cout.precision();
cout << sqrt(res_sigma / n) << endl; return ;
}

OpenJudge/Poj 1191 棋盘分割的更多相关文章

  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 棋盘分割 动态规划

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

  4. POJ 1191 棋盘分割

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

  5. POJ 1191棋盘分割问题

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

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

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

  7. POJ - 1191 棋盘分割 记忆递归 搜索dp+数学

    http://poj.org/problem?id=1191 题意:中文题. 题解: 1.关于切割的模拟,用递归 有这样的递归方程(dp方程):f(n,棋盘)=f(n-1,待割的棋盘)+f(1,割下的 ...

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

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

  9. POJ 1191 棋盘分割(DP)

    题目链接 题意 : 中文题不详述. 思路 : 黑书上116页讲的很详细.不过你需要在之前预处理一下面积,那样的话之后列式子比较方便一些. 先把均方差那个公式变形, 另X表示x的平均值,两边平方得 平均 ...

随机推荐

  1. ExtJs5.1.1使用中问题集锦

    1.获取grid filter对象:  grid.getStore().getFilters().items 2.获取grid filter后把filter对象转换成json格式字符串:grid.ge ...

  2. hdu 5445 Food Problem 多重背包

    Food Problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5 ...

  3. IOS - 常用宏定义和功能方法

    可能不定期添加新的东西 github地址:https://github.com/yuqingzhude/CommonUseDemo /************************Tools**** ...

  4. python的内存管理机制 图解+Django Web开发学习笔记

    http://www.cnblogs.com/CBDoctor/p/3781078.html http://www.cnblogs.com/vamei/p/3232088.html http://bl ...

  5. [JavaScript]转--如何让JS代码高大上

    原文出处:http://www.cnblogs.com/wenber/p/3630373.html 1,创造简短的写法 你可以这么写: 1 var slice = Array.prototype.sl ...

  6. QT5中如何自定义窗口部件

    提升法 eg.(定义一个新的QLable部件)1.定义一个类class Label : public base, public QLabel //可以支持多重继承2.在qt creator中打开ui编 ...

  7. 结合 category 工作原理分析 OC2.0 中的 runtime

    绝大多数 iOS 开发者在学习 runtime 时都阅读过 runtime.h 文件中的这段代码: struct objc_class { Class isa  OBJC_ISA_AVAILABILI ...

  8. How to solve GM MDI cannot complete the installation

    Dear Joy, I have a problem using GM MDI diagnostic tool. When I installed it on my laptop, the tool ...

  9. 自定义控件(视图)1期笔记02:View的绘制流程

    1. 引言: 来自源码的3个方法: (1)public final void measure():测量,用来控制控件的大小,final不建议覆写 (2)public void layout():布局, ...

  10. Android(java)学习笔记121:android.intent.action.MAIN 与 android.intent.category.LAUNCHER 理解

    先看看网路上的说法: android.intent.action.MAIN决定应用程序最先启动的 Activity android.intent.category.LAUNCHER决定应用程序是否显示 ...