UVA - 1456(cellular network 概率dp)
来源:互联网 发布:福州理工学院知乎 编辑:程序博客网 时间:2024/05/24 04:54
首先,要把概率从小到大排序,原因很简单,在期望表达式中同样的决策方案人数越多的项占有的比重越小越好;
然后直接dp即可;d[ i ][ j ] 代表到i位置已经分了几组剩下分配的最大期望;
#include <cstdio>#include <map>#include <cmath>#include <iostream>#include <cstring>#include <algorithm>#include <vector>using namespace std;const int inf = 1000;const int maxn = 105;double d[maxn][maxn],w[maxn],sum[maxn];bool vis[maxn][maxn];int n,m;double Sum(int x,int y){ return w[y]-w[x-1];}double dp(int i,int j){ if(vis[i][j]) return d[i][j]; vis[i][j] = true; if(i==n&&j<m) return d[i][j]=inf; if(j==m-1){ return d[i][j] = n*Sum(i+1,n); } d[i][j]=inf; for(int k=i+1;k<=n;k++){ d[i][j]=min(d[i][j],dp(k,j+1)+k*Sum(i+1,k)); } return d[i][j];}int cmp(const double a,const double b){ return a > b;}int main(){ int T; scanf("%d",&T); while(T--){ scanf("%d %d",&n,&m); int he=0; for(int i=1;i<=n;i++){ scanf("%lf",&sum[i]); he+=sum[i]; } w[0]=0; for(int i=1;i<=n;i++){ w[i]=sum[i]/he; } sort(w+1,w+n+1,cmp); for(int i=1;i<=n;i++){ w[i]=w[i]+w[i-1]; } memset(vis,false,sizeof(vis)); printf("%.4lf\n",dp(0,0)); } return 0;}
0 0
- Uva 1456 - Cellular Network 概率dp
- UVA 1456 Cellular Network 贪心+概率dp
- UVA - 1456(cellular network 概率dp)
- UVa 1456 - Cellular Network(概率DP)
- uva 1456 - Cellular Network (贪心+概率+dp)
- UVaLive 4731 UVa 1456 - Cellular Network(概率DP 贪心)
- uva 1456 - Cellular Network 蜂窝网络 概率DP
- UVA 1456 - Cellular Network(DP)
- UVA 1456 Cellular Network(dp)
- UVA 1456 - Cellular Network(dp + 贪心)
- uva 1456 - Cellular Network(dp + 贪心)
- UVA 1456 Cellular Network(贪心,DP)
- UVA 1456-Cellular Network(DP)
- UVA - 1456 Cellular Network
- UVA4731-Cellular Network(概率dp)
- uva live 4731 Cellular Network 线性dp
- UVA1456|LA4731------Cellular Network------带贪心的概率型DP
- UVALive 4731 Cellular Network 【dp】
- 数据库存储过程加密与解密测试了SQL2005可以用
- 17周(结构体计算天数 )
- 互联网产品的哪些技术和设计可以申请专利?
- [Hb] 读《汇编语言》I
- QQ去除未读状态的动画
- UVA - 1456(cellular network 概率dp)
- 仿360工具栏
- NSIS开始安装时检查**.exe是否正在运行
- shader实现灰阶图
- mybatis spring 配置文件问题
- 第17周项目 1 数组排序 指针
- Java学习笔记——应用矢量和迭代器来实现类似链表的功能
- 嘿嘿,今天要吃汤圆吃咯
- 第十七周 项目6.5 读取文件中数据并处理