题目大意:

手机在蜂窝网络中的定位是一个基本问题。如果蜂窝网络已经得知手机处于c1, c2,…,cn这些区域中的一个。最简单的方法是同一时候在这些区域中寻找手机。但这样做非常浪费带宽。

因为蜂窝网络中能够得知手机在这不同区域中的概率。因此一个折中的方法就是把这些区域分成w组,然后依次訪问。比方。已知手机可能位于5个区域中,概率分别为0.3、0.05、0.1、0.3和0.25,w=2,则一种方法是先同一时候訪问{c1,c2,c3},再同一时候訪问{c4,c5},訪问区域数的数学期望为3*(0.3+0.05+0.1)+(3+2)*(0.3+0.25)=4.1。还有一种方法是先同一时候訪问{c1,c4}。再訪问{c2,c3,c5},訪问区域数的数学期望为2×(0.3+0.3)+(3+2)×(0.05+0.1+0.25)=3.2。

解题思路:

由公式能够发现。为了让总期望值最小,应该让概率大的区域尽量放在前面去訪问。

所以先把全部概率从大到小排序一遍。然后分组时,就能够取连续的一段分为一组了。

f[i][j]表示: 前i个,分成j组的最小期望值

f[i][j] = min{ f[k-1][j] + i*sum[k~i], 1<=k<=i}

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std; int main() {
int T;
scanf("%d", &T);
while (T--) {
int n, w;
double sum[110] = {0}, DP[110][110] = {0}, total = 0;
scanf("%d%d", &n, &w);
for (int i = 1; i <= n; i++) {
scanf("%lf", &sum[i]);
total += sum[i];
}
sort(sum + 1, sum + n + 1, greater<double>()); for (int i = 1; i <= n; i++)
sum[i] = sum[i] / total + sum[i-1]; for (int i = 1; i <= n; i++) {
DP[i][0] = 0x3f3f3f3f;
for (int j = 1; j <= w; j++) {
DP[i][j] = 0x3f3f3f3f;
for (int k = 1; k <= i; k++)
DP[i][j] = min(DP[i][j], DP[k-1][j-1] + i * (sum[i] - sum[k-1]));
}
} printf("%.4lf\n", DP[n][w]);
}
return 0;
}

UVA - 1456 Cellular Network的更多相关文章

  1. DP + 概率 + 贪心 UVA 1456 Cellular Network

    题目传送门 题意:(摘自LRJ<训练指南>) 手机在蜂窝网络中的定位是一个基本问题.假设蜂窝网络已经得知手机处于c1, c2,…,cn这些区域中的一个,最简单的方法是同时在这些区域中寻找手 ...

  2. UVA 1456 六 Cellular Network

    Cellular Network Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit S ...

  3. Educational Codeforces Round 15 C. Cellular Network(二分)

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  4. Educational Codeforces Round 15 Cellular Network

    Cellular Network 题意: 给n个城市,m个加油站,要让m个加油站都覆盖n个城市,求最小的加油范围r是多少. 题解: 枚举每个城市,二分查找最近的加油站,每次更新答案即可,注意二分的时候 ...

  5. Codeforces Educational Codeforces Round 15 C. Cellular Network

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  6. cf702C Cellular Network

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  7. UVA 1386 - Cellular Automaton(循环矩阵)

    UVA 1386 - Cellular Automaton option=com_onlinejudge&Itemid=8&page=show_problem&category ...

  8. Educational Codeforces Round 15_C. Cellular Network

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  9. codeforces 702C Cellular Network 2016-10-15 18:19 104人阅读 评论(0) 收藏

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. html5的audio实现高仿微信语音播放效果

    效果图 前台大体呈现效果图如下: 点击就可以播放mp3格式的录音.点击另外一个录音,当前录音停止! 思路 关于播放动画,这个很简单,我们可以用css3的逐帧动画来实现.关于逐帧动画,我之前的文章也写过 ...

  2. 清除DNS缓存(解决能上QQ但是无法上网页问题)

    ipconfig/displaydnsipconfig/flushdns

  3. IDEA创建lo4j模板

    复制文字到文本框中: log4j.rootLogger=DEBUG,stdout log4j.logger.org.mybatis=DEBUG log4j.appender.stdout=org.ap ...

  4. 20165235 祁瑛 2018-4 《Java程序设计》第六周学习总结

    20165235 祁瑛 2018-4 <Java程序设计>第六周学习总结 教材学习内容总结 常用实用类 (一)1.String类是final类型的,String类型常量也是对象.2.可以使 ...

  5. scrapy之Crawspider 腾讯招聘实战案例

    1. 在虚拟机中cd到项目目录,再运行下面代码创建spider文件: scrapy genspider -t crawl test www.baidu.com 2. spider.py代码 impor ...

  6. Java常用API——时间类

    前言:Java.util.*工具包中,包含了集合框架,旧集合类,事件模型,日期和时间设施,国际化和其他使用程序类 (字符串.随机数生成器和位数组) 一.日期类Date 1.概述 Date是一个薄包装类 ...

  7. Codeforces 1105C Ayoub and Lost Array (计数DP)

    <题目链接> 题目大意: 有一个长度为 n 的数列的未知数列,数列的每一个数的值都在区间 [l,r]  的范围内.现在问你能够构成多少个这样的数组,使得数组内的所有数的和能够被 3 整除. ...

  8. spring cloud 详解

    https://www.cnblogs.com/qdhxhz/p/9601170.html SpringCloud(8)---zuul权限校验.接口限流 https://blog.csdn.net/c ...

  9. flex 布局的复习

  10. MySQL5.7.23 VS MySQL5.6.21 分区表性能对比测试

    为评估MySQL从5.6.21升级到5.7.23版本的性能,针对分区表的读写做了对比测试. [测试环境] 1. 两台HP380的物理机,配置一致,CPU:Intel(R) Xeon(R) CPU E5 ...