题目大意:

手机在蜂窝网络中的定位是一个基本问题。如果蜂窝网络已经得知手机处于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. netty01(长短连接、java)

    使用netty需要添加依赖包 netty版本:netty-5.0.0.Alpha2 http://files.cnblogs.com/files/applerosa/netty-5.0.0.Alpha ...

  2. 事件(Event)(onclick,onchange,onload,onunload,onfocus,onblur,onselect,onmuse)【转载】

    ylbtech-Event:事件(Event)对象 事件(Event) HTML 4.0 事件属性 onclick onchange onload onunload onselect onmouse ...

  3. Floyd算法-傻子也能看懂的弗洛伊德算法(转)

                暑假,小哼准备去一些城市旅游.有些城市之间有公路,有些城市之间则没有,如下图.为了节省经费以及方便计划旅程,小哼希望在出发之前知道任意两个城市之前的最短路程.          ...

  4. 安卓开发中SpannableString之富文本显示效果

    SpannableString其实和String一样,都是一种字符串类型,SpannableString可以直接作为TextView的显示文本,不同的是SpannableString可以通过使用其方法 ...

  5. POJ-1679 The Unique MST (判断最小生成树的唯一性)

    <题目链接> 题目大意: 给定一张无向图,判断其最小生成树是否唯一. 解题分析: 对图中每条边,扫描其它边,如果存在相同权值的边,则标记该边:用kruskal求出MST. 如果MST中无标 ...

  6. Linux命令集

    系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) uname -r 显示正在使用的内核版本 dmidecode -q 显示硬件系统部件 - (SMBIOS ...

  7. scrapy 安装

    windows 1.wheelpip install wheel2.lxmlhttp://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml3.PyOpensslhttp ...

  8. Xamarin Essentials教程振动Vibration

    Xamarin Essentials教程振动Vibration   振动是提醒用户的有效方式,尤其是声音提示效果不明显的场景中,如吵杂的环境中,手机放到包中.在很多的游戏中,振动还用来模拟游戏特效,如 ...

  9. VeeamOne(Free Edition 9.5 )-安装与配置

    ---恢复内容开始--- Veeam ONE则主要用于监控平台之用,可以监控Veeam Backup & Replication的备份及同步情况,也可以监控VMware vSphere虚拟化平 ...

  10. 潭州课堂25班:Ph201805201 django 项目 第二十二课 文章主页 新闻列表页面滚动加载,轮播图后台实现 (课堂笔记)

    新建static/js/news/index.js文件 ,主要用于向后台发送请求, // 新建static/js/news/index.js文件 $(function () { // 新闻列表功能 l ...