POJ 1191 棋盘分割
来源:互联网 发布:淘宝店铺层级怎么算 编辑:程序博客网 时间:2024/05/22 06:32
题目链接
题意:中文题就不说了。。。
分析:把式子化简下就是求sigma(xi^2)的最小值。dp[x1][y1][x2][y2][k]表示在(x1,y1)和(x2,y2 )的矩形内切第k刀。则可以横切也可以纵切。
dp[k][x1][y1][x2][y2]=min(min(dp[k][x1][y1][x2][y2],dp[k-1][x1][y1][t][y2]+dp[0][t+1][y1][x2][y2]),dp[0][x1][y1][t][y2]+dp[k-1][t+1][y1][x2][y2]);
dp[k][x1][y1][x2][y2]=min(min(dp[k][x1][y1][x2][y2],dp[k-1][x1][y1][x2][t]+dp[0][x1][t+1][x2][y2]),dp[0][x1][y1][x2][t]+dp[k-1][x1][t+1][x2][y2]);
#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>#include <iomanip>#include<iostream>using namespace std;const double inf=(double)(1<<30);double dp[15][9][9][9][9];double sum[9][9];double a[9][9];double count(int x1,int y1,int x2,int y2){ double res=sum[x2][y2]-sum[x2][y1-1]-sum[x1-1][y2]+sum[x1-1][y1-1]; return res*res;}int main(void){ int n; double tot; while(scanf("%d",&n)==1) { tot=0; memset(sum,0,sizeof(sum)); for(int i=1;i<=8;i++) { for(int j=1;j<=8;j++) { scanf("%lf",&a[i][j]); tot+=a[i][j]; sum[i][j]=sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1]+a[i][j]; } } for(int x1=1;x1<=8;x1++) { for(int y1=1;y1<=8;y1++) { for(int x2=x1;x2<=8;x2++) { for(int y2=y1;y2<=8;y2++) dp[0][x1][y1][x2][y2]=count(x1,y1,x2,y2); } } } for(int k=1;k<n;k++) { for(int x1=1;x1<=8;x1++) { for(int y1=1;y1<=8;y1++) { for(int x2=x1;x2<=8;x2++) { for(int y2=y1;y2<=8;y2++) { dp[k][x1][y1][x2][y2]=inf; for(int t=x1;t<x2;t++) dp[k][x1][y1][x2][y2]=min(min(dp[k][x1][y1][x2][y2],dp[k-1][x1][y1][t][y2]+dp[0][t+1][y1][x2][y2]),dp[0][x1][y1][t][y2]+dp[k-1][t+1][y1][x2][y2]); for(int t=y1;t<y2;t++) dp[k][x1][y1][x2][y2]=min(min(dp[k][x1][y1][x2][y2],dp[k-1][x1][y1][x2][t]+dp[0][x1][t+1][x2][y2]),dp[0][x1][y1][x2][t]+dp[k-1][x1][t+1][x2][y2]); } } } } } double ans=dp[n-1][1][1][8][8]*1.0/n - ((double)tot*1.0/n)*((double)tot*1.0/n); // printf("%.3lf\n",(double)sqrt(ans)); cout<<setprecision(3)<<fixed<<sqrt(ans)<<endl; } return 0;}
0 0
- POJ 1191棋盘分割
- poj 1191 棋盘分割
- Poj 1191 棋盘分割
- poj 1191 棋盘分割
- POJ 1191 棋盘分割
- poj 1191棋盘分割
- poj 1191 棋盘分割
- POJ-1191-棋盘分割
- POJ 1191 棋盘分割
- poj 1191 棋盘分割
- poj 1191 棋盘分割
- POJ 1191 棋盘分割
- POJ 1191 棋盘分割
- POJ 1191 棋盘分割
- POJ 1191 棋盘分割
- POJ 1191--棋盘分割
- POJ 1191 棋盘分割
- poj 1191 棋盘分割
- NOIP 2015 信息传递
- C++ int、long、double、char所占字节数和表示范围
- POJ 3977 Subset (折半枚举)
- maven+cxf编写RESTful风格webservice
- 架构稳定性
- POJ 1191 棋盘分割
- 速度控制与转矩控制的区别
- List简述
- android spice 协议入门
- java回忆录—常量和变量
- NOIP 2010 乌龟棋
- 2820: YY的GCD
- 获取进程默认可以打开的最大文件描述符数
- .net 串口通讯(蓝屏,死锁,卡死)