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& ...
随机推荐
- computed配合watch监听对象数据
- KMP + BZOJ 4974 [Lydsy1708月赛]字符串大师
KMP 重点:失配nxtnxtnxt数组 意义:nxt[i]nxt[i]nxt[i]表示在[0,i−1][0,i-1][0,i−1]内最长相同前后缀的长度 图示: 此时nxt[i]=jnxt[i]=j ...
- 13-Flutter移动电商实战-ADBanner组件的编写
1.AdBanner组件的编写 我们还是把这部分单独出来,需要说明的是,这个Class你也是可以完全独立成一个dart文件的.代码如下: 广告图片class AdBanner extends Stat ...
- LeetCode 801. Minimum Swaps To Make Sequences Increasing
原题链接在这里:https://leetcode.com/problems/minimum-swaps-to-make-sequences-increasing/ 题目: We have two in ...
- LeetCode 1130. Minimum Cost Tree From Leaf Values
原题链接在这里:https://leetcode.com/problems/minimum-cost-tree-from-leaf-values/ 题目: Given an array arr of ...
- [转载]XML非法字符的处理
https://blog.csdn.net/qq_36330228/article/details/84779390 static void Main(string[] args) { string ...
- 如何用okr做好目标规划
有朋友和我吐槽公司总是规划一个个振奋人心的目标,让大家对工作充满了热情.然而好的开头却缺少追踪反馈没有好的结尾,那些大家所渴望达成的目标随着时间的流逝便逐渐没有了音信,不再有人主动提起,团队成员迎来的 ...
- maven install
1. install maven under ubuntu apt install maven 2 speed up package download vim ~/.m2/settings.xml & ...
- 深搜的剪枝技巧(三)——Sticks(可行性剪枝、上下界剪枝、最优性剪枝)
小木棍(最优性剪枝.可行性剪枝) 一.问题描述 乔治有一些同样长的小木棍,他把这些木棍随意砍成几段,已知每段的长都不超过 50 .现在,他想把小木棍拼接成原来的样子,但是却忘记了自己开始时有多少根木棍 ...
- shell 查看目前机器listen的所有端口
netstat -lnp 这条命令的意思是列出系统里面监听网络连接的端口号和相应的进程PID.参数说明:-t:表示列出TCP连接(也可以加上-u参数表示同时列出UDP网络连接)-l:表示列出正在网络监 ...