UVaLive 4731 Cellular Network (期望DP)
题意:手机在蜂窝网络中的定位是一个基本问题,假设蜂窝网络已经得知手机处于c1,c2,,,cn这些区域中的一个,最简单的方法是同时在这些区域中寻找手机,
但这样做很浪费带宽,由于蜂窝网络中可以得知手机在这不同区域中的概率,因此一个折中的办法就是把这些区域分成w组,然后依次访问,求最小的访问区域数的期望值。
析:dp[i][j] 表示第 i 个属于 j 组的期望最小值。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#define debug() puts("++++");
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 100 + 5;
const int mod = 2000;
const int dr[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
return r >= 0 && r < n && c >= 0 && c < m;
}
int a[maxn];
int dp[maxn][maxn];
int sum[maxn]; int main(){
int T; cin >> T;
while(T--){
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; ++i) scanf("%d", a+i);
sort(a+1, a+n+1, greater<int>());
sum[0] = 0;
for(int i = 1; i <= n; ++i) sum[i] = sum[i-1] + a[i]; memset(dp, INF, sizeof dp);
memset(dp[0], 0, sizeof dp[0]);
for(int i = 1; i <= n; ++i){
for(int j = 1; j <= m; ++j){
for(int k = j-1; k < i; ++k){
int t = dp[k][j-1] + (sum[i] - sum[k]) * i;
dp[i][j] = min(dp[i][j], t);
}
}
}
printf("%.4f\n", (double)dp[n][m] / sum[n]);
}
return 0;
}
UVaLive 4731 Cellular Network (期望DP)的更多相关文章
- UVALive 4731 Cellular Network(贪心,dp)
分析: 状态是一些有序的集合,这些集合互不相交,并集为所有区域.显然枚举集合元素是哪些是无法承受的, 写出期望的计算式,会发现,当每个集合的大小确定了以后,概率大的优先访问是最优的. 因此先对u从大到 ...
- 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-1419】Red is good 概率期望DP
1419: Red is good Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 660 Solved: 257[Submit][Status][Di ...
- [NOIP2016]换教室 D1 T3 Floyed+期望DP
[NOIP2016]换教室 D1 T3 Description 对于刚上大学的牛牛来说, 他面临的第一个问题是如何根据实际情况中情合适的课程. 在可以选择的课程中,有2n节课程安排在n个时间段上.在第 ...
- HDU 4336 Card Collector (期望DP+状态压缩 或者 状态压缩+容斥)
题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率,每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 析:期望DP,是很容易看出来的,然后由 ...
- 【BZOJ-4008】亚瑟王 概率与期望 + DP
4008: [HNOI2015]亚瑟王 Time Limit: 20 Sec Memory Limit: 512 MBSec Special JudgeSubmit: 832 Solved: 5 ...
- 期望dp BZOJ3450+BZOJ4318
BZOJ3450 概率期望DP f[i]表示到i的期望得分,g[i]表示到i的期望长度. 分三种情况转移: ① s[i]=‘x’:f[i]=f[i-1],g[i]=0 ② s[i]=‘o’:f[i]= ...
- HDU 4405 期望DP
期望DP算是第一题吧...虽然巨水但把思路理理清楚总是好的.. 题意:在一个1×n的格子上掷色子,从0点出发,掷了多少前进几步,同时有些格点直接相连,即若a,b相连,当落到a点时直接飞向b点.求走到n ...
随机推荐
- sql server单引号和双引号的区别
--当 SET QUOTED_IDENTIFIER 为 ON 时,标识符可以由双引号分隔,而文字必须由单引号分隔--当 SET QUOTED_IDENTIFIER 为 OFF(默认值)时,表达式中的文 ...
- ABAP div / mod的用法
1.divdiv是用于取两数相除的商的,c = a div b,得到的c的值就是a除b的商.2.// 是用于取两数相除的结果的.c = a / b,如果c是i数据类型的,这个语法会进行四舍五入的.3. ...
- keras:Exception: Error when checking model target
问题: 用keras的functional API搭建多输入多输出模型时,报错某个输出层对应的类标数组大小与模型中不一致. 解决办法:升级keras到最新版(doge脸)keras迭代太快了啊摔,总有 ...
- 使用vscode写typescript(node.js环境)起手式
动机 一直想把typescript在服务端开发中用起来,主要原因有: javascript很灵活,但记忆力不好的话,的确会让你头疼,看着一月前自己写的代码,一脸茫然. 类型检查有利有敝,但在团队开发中 ...
- linux系统 标准目录及其内容
路径名 操作系统 内容 /bin 所有 最核心的操作系统命令 /boot LS 内核和加载内核所需的文件 /dev 所有 伪终端,磁盘,打印机等的设备项 /etc 所有 关键的启动文件和配置文件 ...
- axios无法在ie9,10,11环境下运行的问题解决
npm install es6-promise --save-dev import promise from 'es6-promise'; promise.polyfill();
- js/html/css做一个简单的图片自动(auto)轮播效果//带注释
FF(firefox)/chrom/ie稳定暂无bug...注意:请自己建立一个images文件,放入几张900*238的图片(注意图片格式和名字与程序中一致). 1. [图片] 1.JPG 2. [ ...
- yt-seo-checklist
YouTube Video Ranking Checklist 1. Create video in 16:9 ratio, 720P (1280x720)pixel 2. Video file na ...
- android自定义控件(四) View中的方法
onFinishInflate() 当View中所有的子控件 均被映射成xml后触发 onMeasure(int, int) 确定所有子元素的大小 onLayout(boolean, int, int ...
- linux中python easy_install命令
centos 下安装 python easy_installcurl -O http://peak.telecommunity.com/dist/ez_setup.pypython ez_setup. ...