UVALive 4731 Cellular Network(贪心,dp)
分析:
状态是一些有序的集合,这些集合互不相交,并集为所有区域。显然枚举集合元素是哪些是无法承受的,
写出期望的计算式,会发现,当每个集合的大小确定了以后,概率大的优先访问是最优的。
因此先对u从大到小排序。定义状态f[i][j]表示从j开始往后分i组的最小期望。
转移是枚举划分k,则有f[i][j] = min{f[i-1][k]+(k-j)*(sum_u(j,n))},k>j
边界f[1][j] = (n-j+1)*(u[j])
处理出u的前缀和
复杂度O(w*n^2)
#include<bits/stdc++.h>
using namespace std; const int maxn = 100+;
int u[maxn];
int f[][maxn];
const int INF = 0x3f3f3f3f; //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int T; cin>>T;
while(T--){
int n,w; scanf("%d%d",&n,&w);
for(int i = ; i <= n; i++) scanf("%d",u+i);
sort(u+,u++n,greater<int>());
for(int i = ; i <= n; i++) u[i] += u[i-];
for(int j = n; j > ; j--){
f[][j] = (n-j+)*(u[n]-u[j-]);
}
for(int i = ; i <= w; i++){
for(int j = ; j <= n; j++){
f[i][j] = INF;
for(int k = j+; k <= n; k++){
f[i][j] = min(f[i-][k]+(k-j)*(u[n]-u[j-]),f[i][j]);
}
}
}
printf("%.4lf\n", f[w][]/(double)u[n]);
}
return ;
}
UVALive 4731 Cellular Network(贪心,dp)的更多相关文章
- UVaLive 4731 Cellular Network (期望DP)
题意:手机在蜂窝网络中的定位是一个基本问题,假设蜂窝网络已经得知手机处于c1,c2,,,cn这些区域中的一个,最简单的方法是同时在这些区域中寻找手机, 但这样做很浪费带宽,由于蜂窝网络中可以得知手机在 ...
- UVA 1456 六 Cellular Network
Cellular Network Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit S ...
- 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 ...
- 【BZOJ-3174】拯救小矮人 贪心 + DP
3174: [Tjoi2013]拯救小矮人 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 686 Solved: 357[Submit][Status ...
- 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 ...
- 【暑假】[实用数据结构]UVAlive 3027 Corporative Network
UVAlive 3027 Corporative Network 题目: Corporative Network Time Limit: 3000MS Memory Limit: 30000K ...
- cf702C Cellular Network
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- 洛谷P3006 [USACO11JAN]瓶颈Bottleneck(堆模拟)
传送门 感觉这题的思路还是挺不错的.然而为啥全网就一个题解而且只有代码……然后我只好看着代码理解了好久…… 题意就是有一棵树,每一个节点向他父亲节点连边,且有一个容量表示每一秒可以经过的牛的数量,每一 ...
- 洛谷P1349 广义斐波那契数列
传送门 话说谁能告诉我矩阵怎么用latex表示…… 差不多就这样 //minamoto #include<iostream> #include<cstdio> #include ...
- Codeforces Round #501 (Div. 3) 1015A Points in Segments (前缀和)
A. Points in Segments time limit per test 1 second memory limit per test 256 megabytes input standar ...
- 关于双端队列 deque 模板 && 滑动窗口 (自出)
嗯... deque 即为双端队列,是c++语言中STL库中提供的一个东西,其功能比队列更强大,可以从队列的头与尾进行操作... 但是它的操作与队列十分相似,详见代码1: 1 #include < ...
- POJ1022 Packing Unit 4D Cubes
题目来源:http://poj.org/problem?id=1022 题目大意: 有一些4维的单位体积的立方体盒子,每个立方体有8个面.要用一个大的4为盒子将它们包起来,求最小的大盒子体积. 输入: ...
- std::ref() 与 &
引言 之前因为调整样式把博客园的样式毁了,所以一直在自己的另一个博客上更新,有兴趣的可以去观望一下:http://blog.yunlambert.top/最近还是把博客园拾起来吧..... 最近看到一 ...
- BZOJ 4165 矩阵 堆
先把每个长为$mina$,宽为$minb$的矩阵扔到堆里,然后由于矩阵中的数都是正的,所以我们每取出来一个矩形,,就把他向四个方向扩张一行,再把这新的且更大的四个矩形扔到堆里.注意判重,于是我比较懒用 ...
- python操作json文件
import json class OperationJson(object): def __init__(self,file_name=None): if file_name: self.file_ ...
- wamp 下运行Drupal慢的解决方法
1.Editing your php.ini and make realpath_cache_size=2M, 2.uncomment skip innodb in your my.cnf(my.in ...
- ASP Session的功能的缺陷以及解决方案
转http://www.cnblogs.com/jhy55/p/3376925.html 目前ASP的开发人员都正在使用Session这一强大的功能,但是在他们使用的过程中却发现了ASP Sessio ...