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 ...
随机推荐
- JSP-模拟银行卡账号密码登录页面跳转
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- Java基础笔记(十一)—— 字符串与数组
字符串的声明与初始化主要两种:String s1=new String("abc"); 或 String s2="abc"; String ...
- Swift几行代码解决UITableView空数据视图问题
tableView空数据问题 一般项目中tableView若数据为空时会有一个提示示意图 为了更好的管理这种提示示意图,笔者利用extension进行了简单的拓展 解决思路 利用swift面向协议的特 ...
- little w and Soda(思维题)
链接:https://ac.nowcoder.com/acm/contest/297/A 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...
- AnkhSVN使用手册
(一) 安装: Subversion客户端安装------AnkhSVN AnkhSVN是一款在VS中管理Subversion的插件,您可以在VS中轻松的提交.更新.添加文件,而不用在命令行或资源管理 ...
- 04.Spring Ioc 容器 - 刷新
基本概念 Spring Ioc 容器被创建之后,接下来就是它的初始化过程了.该过程包含了配置.刷新两个步骤 . 刷新由 Spring 容器自己实现,具体发生在 ConfigurableApplicat ...
- LeetCode 233 Number of Digit One 某一范围内的整数包含1的数量
Given an integer n, count the total number of digit 1 appearing in all non-negative integers less th ...
- (转)深入浅出linux系统umask值及其对应的文件权限讲解
浅出linux系统umask值及其对应的文件权限讲解 原文:http://blog.51cto.com/oldboy/1060032 缘起:1.此文的撰写特别为感谢51cto的博客工作人员和领导,老男 ...
- Hive 基本语法操练(三):分区操作和桶操作
(一)分区操作 Hive 的分区通过在创建表时启动 PARTITION BY 实现,用来分区的维度并不是实际数据的某一列,具体分区的标志是由插入内容时给定的.当要查询某一分区的内容时可以采用 WHER ...
- Docker最全教程之使用PHP搭建个人博客站点(二十二)
目录 官方镜像 编写简单的Hello world! 1. 编写Hello world! 2. 编写Dockerfile 3. 构建并运行 4. 直接使用PHP Docker镜像运行PHP脚本 构建自 ...