POJ1191 棋盘分割
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: Accepted:
题目链接:
http://poj.org/problem?id=1191
解题思路:
关键是方程式的化简,思路清晰,整个题的难度不大。
AC代码(课程PPT)
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iomanip> using namespace std; int s[][]; //每个格子的分数
int sum[][]; //(1,1)到(i,j)的矩形的分数之和
int res[][][][][]; //fun的记录表 int calSum(int x1, int y1, int x2, int y2)//(x1,y1)到(x2,y2)的矩形的分数之和
{
return sum[x2][y2]-sum[x2][y1-]-sum[x1-][y2]+sum[x1-][y1-];
} int fun(int n, int x1, int y1, int x2, int y2)
{
int t, a, b, c, e, MIN = ;
if (res[n][x1][y1][x2][y2] != -)
return res[n][x1][y1][x2][y2];
if (n == )
{
t = calSum(x1, y1, x2, y2);
res[n][x1][y1][x2][y2] = t * t;
return t * t;
}
for (a = x1; a < x2; a++)
{
c = calSum(a + , y1, x2, y2);
e = calSum(x1, y1, a, y2);
t = min(fun(n - , x1, y1, a, y2) + c * c, fun(n - , a + , y1, x2, y2) + e * e);
if (MIN > t) MIN = t;
}
for (b = y1; b < y2; b++)
{
c = calSum(x1, b + , x2, y2);
e = calSum(x1, y1, x2, b);
t = min(fun(n - , x1, y1, x2, b) + c * c, fun(n - , x1, b + , x2, y2) + e * e);
if (MIN > t) MIN = t;
}
res[n][x1][y1][x2][y2] = MIN;
return MIN;
}
int main() {
memset(sum, , sizeof(sum));
memset(res, -, sizeof(res)); //初始化记录表
int n;
cin>>n;
for (int i=; i<; 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*fun(n,,,,)-sum[][]*sum[][];
cout<<setiosflags(ios::fixed)<<setprecision()<<sqrt(result/(n*n))<<endl;
return ;
}
POJ1191 棋盘分割的更多相关文章
- poj1191 棋盘分割【区间DP】【记忆化搜索】
棋盘分割 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16263 Accepted: 5812 Description ...
- poj1191棋盘分割——区间DP
题目:http://poj.org/problem?id=1191 分析题意,可知每次要沿棋盘中的一条线把一块一分为二,取其中一块继续分割: σ最小经分析可知即为每块的xi和的平方最小: 故用区间DP ...
- POJ1191 棋盘分割(DP)
化简一下那个方差得到:$$\sqrt\frac{(\Sigma_{i=1}^nx_i)-n\bar x^2}{n}$$ 除了$\Sigma_{i=1}^nx_i$这部分未知,其余已知,而那部分显然越大 ...
- POJ1191棋盘分割
题目:http://poj.org/problem?id=1191 1.分析式子!!! 发现xba是定值,σ的大小仅和∑ xi^2 有关.故dp条件是平方和最小. 2.分出一块就像割掉一条,只需枚举从 ...
- poj1191 棋盘分割。 dp
连接:http://poj.org/problem?id=1191 思路:额,其实就是直接搞记录一下就可以了. #include <stdio.h> #include <string ...
- 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& ...
随机推荐
- python开发笔记-DataFrame的使用
今天详细做下关于DataFrame的使用,以便以后自己可以翻阅查看 DataFrame的基本特征: 1.是一个表格型数据结构 2.含有一组有序的列 3.大致可看成共享同一个index的Series集合 ...
- oracle 将与本端(name)联系的人取出
本人与其他所有人认识的SQL: 首先新建测试表 create table DIM_IA_TEST6 ( NAME ), OTHERNAME ) ) 插入数据 --如果没有重复的记录,则不用去重使用un ...
- shell脚本中向hive动态分区插入数据
在hive上建表与普通分区表创建方法一样: CREATE TABLE `dwa_m_user_association_circle`( `device_number` string, `oppo_nu ...
- django-改写manage类-objects
user/models.py中 class AddressManage(models.Manager): '''地址模型管理类''' def get_default_addr(self, user): ...
- php+tcpdf如何把生成的pdf文件保存在服务端
tcpdf组件目前应用得非常广泛,但是对于如何把生成的pdf文件自动保存在服务端却很少有人提及.让我们先来看看标准输出代码: //服务器存档模式 $pdf->Output('output.p ...
- Bias, Variance and the Trade-off
偏差,方差以及两者权衡 偏差是由模型简化的假设,使目标函数更容易学习. 一般来说,参数化算法有很高的偏差,使它们学习起来更快,更容易理解,但通常不那么灵活.反过来,它们在复杂问题上的预测性能更低,无法 ...
- LeetCode 439. Ternary Expression Parser
原题链接在这里:https://leetcode.com/problems/ternary-expression-parser/description/ 题目: Given a string repr ...
- A - Happy Birthday, Polycarp!
Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4) A. Happy Birthday, Polyc ...
- java 数据库迁移工具 flyway
官方 https://github.com/flyway/flyway 简易demo https://github.com/deadzq/flyway-demo 主要在配置文件上做改动
- Python 下载超大文件
使用python下载超大文件, 直接全部下载, 文件过大, 可能会造成内存不足, 这时候要使用requests 的 stream模式, 主要代码如下 iter_content:一块一块的遍历要下载的内 ...