题目传送门

题意:(摘自LRJ《训练指南》)

手机在蜂窝网络中的定位是一个基本问题。假设蜂窝网络已经得知手机处于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。

分析:贪心思想,概率大的在前面访问。dp[i][j] 表示前i个分成j组的期望

代码:

/************************************************
* Author :Running_Time
* Created Time :2015-8-31 17:10:56
* File Name :UVA_1456.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e2 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int u[N];
double dp[N][N], p[N], sum[N]; int main(void) {
int T; scanf ("%d", &T);
while (T--) {
int n, w; scanf ("%d%d", &n, &w);
int tot = 0;
for (int i=1; i<=n; ++i) {
scanf ("%d", &u[i]); tot += u[i];
} sort (u+1, u+1+n, greater<int> ());
sum[0] = 0;
for (int i=1; i<=n; ++i) {
p[i] = u[i] * 1.0 / tot;
sum[i] = sum[i-1] + p[i];
}
for (int i=1; i<=n; ++i) {
dp[i][0] = INF;
for (int j=1; j<=w; ++j) {
dp[i][j] = INF;
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 ("%.4f\n", dp[n][w]);
} return 0;
}

  

DP + 概率 + 贪心 UVA 1456 Cellular Network的更多相关文章

  1. UVA - 1456 Cellular Network

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

  2. UVA 1456 六 Cellular Network

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

  3. UVA 11427 Expect the Expected(DP+概率)

    链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35396 [思路] DP+概率 见白书. [代码] #include&l ...

  4. 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 ...

  5. 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. Educational Codeforces Round 15 Cellular Network

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

  7. 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 ...

  8. tyvj P1864 [Poetize I]守卫者的挑战(DP+概率)

    P1864 [Poetize I]守卫者的挑战 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 打开了黑魔法师Vani的大门,队员们在迷宫般的路上漫无目的地搜 ...

  9. cf702C Cellular Network

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

随机推荐

  1. Linux信号通讯编程

    信号通讯流程为: ①进程A/内核选择信号 ②发送信号 ③进程B接收信号并处理 Linux系统支持的全部信号均定义在/usr/include/asm/signal.h.当中常见的信号有: ①SIGKIL ...

  2. 移动端CSS小结

    Meta 标签 <meta name="viewport"  content="width=device-width, user-scalable=no, init ...

  3. 纠结的链接——ln、ln -s、fs.symlink、require

    纠结的链接--ln.ln -s.fs.symlink.require 提交 我的留言 加载中 已留言 inode 我们首先来看看 linux 系统里面的一个重要概念:inode. 我们知道,文件存储在 ...

  4. LUA协程复用

    -----协程复用根函数 local function routine(fun, args) while (fun) do fun, args = coroutine.yield(fun(table. ...

  5. jquery全局变量---同步请求设置

    1.同步 $.ajaxSetup({ async: false }); 2.异步 $.ajaxSetup({   async: true   }); 3.说明:我们一般使用同步完要恢复异步.由于js默 ...

  6. vux-uploader 图片上传组件

    1.网址:https://github.com/greedying/vux-uploader 2.安装 npm install vux-uploader --save npm install --sa ...

  7. #include<> 和 #include""的区别

    #include< file >编译程序会先到标准函数库中找文件 #include”file” 编译程序会先从当前目录中找文件 参考原文 转: 在C程序中包含文件有以下两种方法: (1)用 ...

  8. 从PRISM开始学WPF(一)WPF?

    从PRISM开始学WPF(一)WPF?   我最近打算学习WPF ,在寻找MVVM框架的时候发现了PRISM,在此之前还从一些博客上了解了其他的MVVM框架,比如浅谈WPF中的MVVM框架--MVVM ...

  9. 说说Windows7 64bits下安装TensorFlow GPU版本会遇到的一些坑

    不多说,直接上干货! 再写博文,回顾在Windows7上安装TensorFlow-GPU的一路坑 Windows7上安装TensorFlow的GPU版本后记 欢迎大家,加入我的微信公众号:大数据躺过的 ...

  10. Pthon的定时任务APScheduler的启动与关闭

    Pthon的定时任务APScheduler的启动与关闭 安装: sudo pip install apscheduler 使用: 直接运行Python文件即可,如 python XXX.py,XXX. ...