UVa1456Cellular Network(概率DP)

Cellular Network

Description

A cellular network is a radio network made up of a number of cells each served by a base station located in the cell. The base station receives call signals from mobile users (mobiles) in the cell
it serves, which then connects the calls to the wired land-line telephone network. When a call is requested to connect to a mobile, the cellular network must know in which cell the mobile is located so that the call is routed to the base station of the cell
appropriately.

Mobiles move from once cell to another in a cellular network. Whenever a mobile reports its new cell as it crosses boundaries of cells, the cellular network would know its exact cell at any time and finding (paging)
the mobile becomes a trivial task. But it is usually infeasible for a mobile to report its new location each time it enters a new cell because of the insufficiencies of resources such as the radio bandwidth. But normally at the time of a call arrival, the
cellular network knows a limited number of cells where the mobile is located. In this situation, a lot of paging strategies are developed to locate a mobile efficiently. The ultimate goal of paging strategies is to minimize both the time delay and cost of
paging until the mobile is found.

Now we define our problem formally. The
location area is the set of n cells
C = {c1, c2,..., cn} such that the mobile is guaranteed to be in one of these cells at the time of a call arrival. Suppose that it is possible to page any subset of these
n cells in a unit of time (paging rounds) and find out if the mobile is located in one of the cells paged. The fastest strategy to find the cell where the mobile is located is to page all the
n cells in the first and only round. However this strategy uses a lot of wireless bandwidth.

In many cases, the cellular network knows about the whereabouts of the mobile. This knowledge can be modeled with
n probability values, where the probability of the mobile being present in a cell can be estimated for each of these
n cells at the time of a call arrival. Let
pi be the probability that the mobile is located at the cell
ci and all the probabilities are independent. A sequential paging strategy is to page the cells sequentially in
n paging rounds terminating once the mobile is found. Then the average cost of paging (number of cells paged),
, and the average paging delay (number of paging rounds) in locating the mobile,
, can be expressed as follows:

(
ixpi), (
ixpi).

The parallel paging strategy is to page the cells in a collection of cells simultaneously. Sequential paging strategy has lower paging cost than parallel paging strategy, but at the expense of larger
paging delay. The method of parallel paging is to partition the cells in a location area into a series of indexed groups referred to as
paging zones. Let Z1,
Z2,..., Zw be the partition of the location area
C (i.e., a partition of C into
w groups), where each Zi is non-empty and corresponds to a distinct paging zone. When a call arrives for a mobile, the cells in the first paging zone
Z1 are paged simultaneously in the first round and then if the mobile is not found in the first round of paging, all the cells in the second paging zone
Z2 are paged, and so on. Let the number of cells in the paging zone
Zi be denoted by
ni = | Zi|, and let
be the corresponding zone probabilities of the users in the paging zone
Zi, where =
pj. Then the average cost of paging (number of cells paged),
, and the average paging delay (number of paging rounds) in locating the mobile,
D, can be expressed as follows:

=
(
)
,
(
ix).

In parallel paging strategy, there is a tradeoff between bandwidth for time. For example, we increases the number of paging zones, then the paging cost could be decreased. If we decrease the number of paging zones, then the paging
cost could be increased. Furthermore, for a fixed number w of paging zones, the paging cost could be different to the strategies how the cells in location area are partitioned.

For example, there are n = 5 cells in a location area
C = {c1, c2,...,
c5} and the probability of each cells in
C are as follows:

ci c1 c2 c3 c4 c5
pi 0.3 0.05 0.1 0.3 0.25

If the cells in C are partitioned into two paging zones
Z1 = {c1, c2,
c3}, Z2 = {c4,
c5}, the average cost of paging, , and the average paging
delay in locating the mobile, , are:

=
n1 + (n1 +
n2) = 3(0.3 + 0.05 + 0.1) + (3 + 2)(0.3 + 0.25) = 3
x 0.45 + 5 x 0.55 = 4.1

= 1
+2 = 1(0.3 + 0.05 + 0.1) + 2(0.3 + 0.25) = 1
x 0.45 + 2 x 0.55 = 1.55

If the cells in C are partitioned into two paging zones
Z1 = {c1, c4},
Z2 = {c2, c3, c5}, the average cost of paging,
, and the average paging delay in locating the mobile,
, are:

=
n1 + (n1 +
n2) = 2(0.3 + 0.3) + (3 + 2)(0.05 + 0.1 + 0.25) = 2
x 0.6 + 5 x 0.4 = 3.2

= 1
+2 = 1(0.3 + 0.3) + 2(0.05 + 0.1 + 0.25) = 1
x 0.6 + 2 x 0.4 = 1.4

Given the number of cells in a location area C, the probabilities of each cells that a mobile is located at the cell, and the fixed number
w of paging zones, write a program to partition the cells in
C into w paging zones such that the average cost of paging to find the location of the mobile is minimized.

Input

Your program is to read from standard input. The input consists of
T test cases. The number of test cases
T is given in the first line of the input. Each test case consists of two lines. The first line of each test case contains two integers. The first integer,
n, is the number of cells in a location area, and the second integer,
w, is the number of paging zones, where
1wn100.
The second line of each test case contains n integers
u1, u2,..., un, where the probability
pi for each cell
ci in C is
pi = ui/(u1 + u2 +
... + un). All integers in the second line are between 1 and 10,000.

Output

Your program is to write to standard output. Print exactly one line for each test case. The line should contain the minimum average cost of paging to find the location of the mobile. The output should have a precision of exactly
4 digits after decimal point. You may round to the 4 digits after decimal point or round off at the 4-th digit after decimal point.

The following shows sample input and output for two test cases.

Sample Input

2
5 2
30 5 10 30 25
5 5
30 5 10 30 25

Sample Output

3.2000
2.3000

题意:手机在蜂窝中的定位问题是一个基本的问题。假设蜂窝网络已经知道手机处于 c1, c2, c3,....cn 这些都区域中的一个,最简单的方法就是同时在这些区域寻找手机。但这样做很浪费时间,由于蜂窝网络可以知道手机在这不同区域的概率,因此折中的方法就是把这些区域分成 w 组, 然后依次访问。比如,已经知道手机可能位于 5 个区域中,概率分别为 0.3, 0.05, 0.1, 0.3, 0.25, w = 2, 其中一种方法是先同时访问 {c1,c2,
c3}, 再同时访问 {c

4,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。

题目给出的不是概率值,是一些整数。 u1,u2,u3,...un,手机在 Ci 的概率是 Pi = ui / (u1+u2+u3+....+un)。

思路:简单的概率DP

先把各个区域的概率值排序,概率大的排前面。再处理前缀和,这样子就可以分为连续的一段一段来处理了。

状态转移方程:

dp [ i,j ]  表示前 i 个分为 j 个连续区间时的最小期望值,把前 k-1 个分为 j-1 个连续区间, 再把 k 到 i 作为一个连续区间。遍历所有 k 求最小值。

dp [ i,j ]  = min { dp [ i,j ],dp [ k-1,j-1 ] + i * ( p [ i ] -
p [ k-1 ] )
}

其中  1 <= i <= n 
,1 <= j <= w
,1 <= k <= i

<span style="font-size:18px;">#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std;

const int INF = 1<<29;
const double PI = acos(-1.0);
const double e = 2.718281828459;
const double eps = 1e-8;
const int MAXN = 110;
double p[MAXN];
double dp[MAXN][MAXN];

bool cmp(double x, double y)
{
    return x > y;
}

int main()
{
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, w;
    int Case;
    cin>>Case;
    while(Case--)
    {
        cin>>n>>w;
        double sum = 0;
        memset(p, 0, sizeof(p));
        for(int i = 1; i <= n; i++)
        {
            cin>>p[i];
            sum += p[i];
        }
        for(int i = 1; i <= n; i++)
        {
            p[i] /= sum;
        }
        sort(p+1, p+1+n, cmp);
        for(int i = 1; i <= n; i++)
        {
            p[i] += p[i-1];
            fill(dp[i], dp[i]+1+w, INF);   // 初始化
        }
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= w; j++)
            {
                for(int k = 1; k <= i; k++)
                {
                    dp[i][j] = min(dp[i][j], dp[k-1][j-1]+(p[i]-p[k-1])*i);
                }
            }
        }
        printf("%.4f\n", dp[n][w]);
    }
    return 0;
}

</span>
时间: 2025-01-09 12:50:48

UVa1456Cellular Network(概率DP)的相关文章

Codeforces 28C [概率DP]

/* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队伍的期望. 思路: 概率dp dp[i][j][k]代表前i个浴室有j个人最长队伍是k的概率. 枚举第i个浴室的人数.然后转移的时候其实是一个二项分布. */ #include<bits/stdc++.h> using namespace std; int jilu[55]; double dp[

hdu 3076 ssworld VS DDD (概率dp)

///题意: /// A,B掷骰子,对于每一次点数大者胜,平为和,A先胜了m次A赢,B先胜了n次B赢. ///p1表示a赢,p2表示b赢,p=1-p1-p2表示平局 ///a赢得概率 比一次p1 两次p0*p1 三次 p0^2*p1,即A赢的概率为p1+p*p1+p^2*p1+...p^n*p1,n->无穷 ///即a_win=p1/(1-p);b_win=p2/(1-p); ///dp[i][j]表示a赢了j次,b赢了i次的概率 ///dp[i][j]=dp[i-1][j]*b_win+dp[

hdu 3853 概率DP 简单

http://acm.hdu.edu.cn/showproblem.php?pid=3853 题意:有R*C个格子,一个家伙要从(0,0)走到(R-1,C-1) 每次只有三次方向,分别是不动,向下,向右,告诉你这三个方向的概率,以及每走一步需要耗费两个能量,问你走到终点所需要耗费能量的数学期望: 回头再推次,思想跟以前的做过的类似 注意点:分母为0的处理 #include <cstdio> #include <cstring> #include <algorithm>

hdu4089(公式推导)概率dp

题意:有n人都是仙剑5的fans,现在要在官网上激活游戏,n个人排成一个队列(其中主角Tomato最初排名为m), 对于队列中的第一个人,在激活的时候有以下五种情况: 1.激活失败:留在队列中继续等待下一次激活(概率p1) 2.失去连接:激活失败,并且出队列然后排到队列的尾部(概率p2) 3.激活成功:出队列(概率p3) 4.服务器瘫:服务器停止服务了,所有人都无法激活了(概率p4) 求服务器瘫痪并且此时Tomato的排名<=k的概率. 解法:ans[i][j]表示i个人出于第j个位置要到目的状

poj3071(概率DP)

题意:淘汰赛制,2^n(n<=7)个队员.给出相互PK的输赢概率矩阵.问谁最有可能赢到最后. 解法:ans[i][j]表示第i个队员第j轮胜出的概率.赢到最后需要进行n场比赛.算出每个人赢到最后的ans[i][n].写出序号的二进制发现一个规律,两个队员i.j如果碰到,那么一定是在第get(i,j)场比赛碰到的.get(i,j)计算的是i和j二进制不同的最高位,这个规律也比较明显. 代码: /****************************************************

【Foreign】开锁 [概率DP]

开锁 Time Limit: 10 Sec  Memory Limit: 256 MB Description Input Output Sample Input 4 5 1 2 5 4 3 1 5 2 2 5 4 3 1 5 3 2 5 4 3 1 5 4 2 5 4 3 1 Sample Output 0.000000000 0.600000000 0.900000000 1.000000000 HINT Main idea 一个宝箱内有一个可以开启别的宝箱的钥匙,可以选择k个宝箱,询问能开

POJ 2151 Check the difficulty of problems (概率DP)

题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 ,求每队至少解出一题且冠军队至少解出N道题的概率. 析:概率DP,dp[i][j][k] 表示第 i 个队伍,前 j 个题,解出 k 个题的概率,sum[i][j] 表示第 i 个队伍,做出 1-j 个题的概率,ans1等于, T个队伍,至少解出一个题的概率,ans2 表示T个队伍,至少解出一个题,但不超过N-1个题的概率,最后用ans1-ans2即可. 代码如下: #pragma comment(linker, "/STA

UVALive 6672 Bonus Cards 概率dp

题意呢 就是有两种售票方式 一种是icpc 一种是其他方式 icpc抢票成功的概率是其他方式的2倍…… 这时 一个人出现了 他通过内幕知道了两种抢票方式各有多少人 他想知道自己如果用icpc抢票成功的概率是多少 用acm抢票成功的概率是多少…… 做过不多的概率dp 还在摸索…… dp[i][j]代表第i轮有j个icpc的人已经有票了…… 当然同时i-j个通过其他方式抢票的人也有票了 这就是用同样的函数搜两次的原理…… 优化一次i<=a 一次是把初始化放到for里…… 第一次见这么卡时间的题……

HDU 4599 Dice (概率DP+数学+快速幂)

题意:给定三个表达式,问你求出最小的m1,m2,满足G(m1) >= F(n), G(m2) >= G(n). 析:这个题是一个概率DP,但是并没有那么简单,运算过程很麻烦. 先分析F(n),这个用DP来推公式,d[i],表示抛 i 次连续的点数还要抛多少次才能完成.那么状态转移方程就是 d[i] = 1/6*(1+d[i+1]) + 5/6*(1+d[1]), 意思就是说在第 i 次抛和上次相同的概率是1/6,然后加上上次抛的和这一次,再加上和上次不同的,并且又得从第1次开始计算. 边界就是