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 ...
随机推荐
- 多校训练hdu --Nice boat(线段树,都是泪)
Nice boat Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total ...
- APache POI emaple ()
Business Plan The BusinessPlan application creates a sample business plan with three phases, weekly ...
- Java面试通关要点汇总整理【终极版】(转载)
简历篇 请自我介绍 请介绍项目 基础篇 基本功 面向对象的特征 final, finally, finalize 的区别 int 和 Integer 有什么区别 重载和重写的区别 抽象类和接口有什么区 ...
- createElement与innerHtml性能比較
js中.动态加入html的方法大致就是两种,一种是document.createElement等方法创建,然后使用Element.appendChild加入,或者是使用Element.innerHTM ...
- [学习笔记]overthewire bandit 通关秘籍
1.第一关 使用putty等工具连入linux即可,注意port等设置. ls 列目录内文件: cat readme,显示文件内容,即可看到密码. 2.第二关 如何查看文件名为-的文件? cat ./ ...
- 连接虚拟机的SQLServer
1.IP可以互相PING通 2.Telnet发现端口没有放开,防火墙新建入账规则开放端口 成功..
- (转载)synchronized代码块
原文:http://blog.csdn.net/luoweifu/article/details/46613015 作者:luoweifu 转载请标名出处 <编程思想之多线程与多进程(1)——以 ...
- 《CMake实践》笔记二:INSTALL/CMAKE_INSTALL_PREFIX【转】
本文转载自:http://www.cnblogs.com/52php/p/5681751.html 四.更好一点的Hello World 没有最好,只有更好 从本小节开始,后面所有的构建我们都将采用 ...
- POJ - 1459 Power Network(最大流)(模板)
1.看了好久,囧. n个节点,np个源点,nc个汇点,m条边(对应代码中即节点u 到节点v 的最大流量为z) 求所有汇点的最大流. 2.多个源点,多个汇点的最大流. 建立一个超级源点.一个超级汇点,然 ...
- manacher求最长回文子串算法
原文:http://www.felix021.com/blog/read.php?2040 首先用一个非常巧妙的方式,将所有可能的奇数/偶数长度的回文子串都转换成了奇数长度:在每个字符的两边都插入一个 ...