DP + 概率 + 贪心 UVA 1456 Cellular Network
题意:(摘自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的更多相关文章
- UVA - 1456 Cellular Network
题目大意: 手机在蜂窝网络中的定位是一个基本问题.如果蜂窝网络已经得知手机处于c1, c2,-,cn这些区域中的一个.最简单的方法是同一时候在这些区域中寻找手机.但这样做非常浪费带宽. 因为蜂窝网络中 ...
- UVA 1456 六 Cellular Network
Cellular Network Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit S ...
- UVA 11427 Expect the Expected(DP+概率)
链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=35396 [思路] DP+概率 见白书. [代码] #include&l ...
- 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 ...
- Educational Codeforces Round 15 C. Cellular Network(二分)
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 15 Cellular Network
Cellular Network 题意: 给n个城市,m个加油站,要让m个加油站都覆盖n个城市,求最小的加油范围r是多少. 题解: 枚举每个城市,二分查找最近的加油站,每次更新答案即可,注意二分的时候 ...
- 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 ...
- tyvj P1864 [Poetize I]守卫者的挑战(DP+概率)
P1864 [Poetize I]守卫者的挑战 时间: 1000ms / 空间: 131072KiB / Java类名: Main 描述 打开了黑魔法师Vani的大门,队员们在迷宫般的路上漫无目的地搜 ...
- cf702C Cellular Network
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- HOST绑定和VIP映射
今天上线需要配置RAL,处理半天,发现是需要HOST和IP分开来配. 比如: curl -H "Host: ktvin.nuomi.com" "http://10.207 ...
- sendEmail实现邮件报警发送
安装wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz tar -xf sendEmail-v ...
- [转] Scalers:刻意练习的本质就是持续行动+刻意学习
原文: http://www.scalerstalk.com/1264-peak-conscious ------------------------------------------------- ...
- influxDB系列(一)
这个是github上面一个人总结的influxDB的操作手册,还不错:https://xtutu.gitbooks.io/influxdb-handbook/content/zeng.html 1. ...
- 使用literal语法格式化字符串
支持arm64之后,格式化字符串的时候会遇到一些问题,主要与NSInteger的定义有关: #if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET ...
- Making User-Managed Backups-17.3、Making User-Managed Backups of Offline Tablespaces and Datafiles
17.3.Making User-Managed Backups of Offline Tablespaces and Datafiles 备份离线的表空间时.须要注意下面指导原则: (1)不能离线s ...
- Orange's_1_win7下搭建环境
工欲善其事,必先利其器. 由于公司电脑工作环境是win7,为了学习于渊的Orange,所以就在windows下配置环境: 1.nasm: nasm汇编 http://www.nasm.us/ ...
- 嵌入式开发之davinci---IPIPE、IPIPEIF and ISIF这三者有什么区别
(1)缩写概念 (2)各自区别 (3)不同sensor 采集接口 (4)采集后的数据链路link (5)8127 中的iss和ipipe的区别 (1)缩写概念 http://www.ti.com.cn ...
- Tomcat9无法启动
闲来无事,重新学习一下Java, 去Tomcat官网下载Tomcat,各种版本,7-8-9,果断下载最新的9,解压后,无需安装,到bin文件夹下启动, 结果总是一闪而过,百度: 1.查看8080是否占 ...
- lucene DocValues——没有看懂
前言: 在Lucene4.x之后,出现一个重大的特性,就是索引支持DocValues,这对于广大的solr和elasticsearch用户,无疑来说是一个福音,这玩意的出现通过牺牲一定的磁盘空间带来的 ...