UVaLive 4731 UVa 1456 - Cellular Network(概率DP 贪心)

Time Limit:3000MS Memory Limit:Unknown 64bit IO Format:%lld & %llu

[]  [Go Back]  [Status]  

Description

Download as PDF

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), $ \overline{​{C}}$ , and the average paging delay (number of paging rounds) in locating the mobile, $ \overline{​{D}}$, can be expressed as follows:

$\displaystyle \overline{​{C}}$ $\displaystyle \sum^{​{n}}_{​{i=1}}$( i x p i), $\displaystyle \overline{​{D}}$ $\displaystyle \sum^{​{n}}_{​{i=1}}$( i x p i).

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 $ \pi_{​{i}}^{}$ be the corresponding zone probabilities of the users in the paging zone Zi, where $ \pi_{​{i}}^{}$ = $ \sum_{​{c_{j} \in Z_{i}}}^{}$pj. Then the average cost of paging (number of cells paged), $ \overline{​{C}}$, and the average paging delay (number of paging rounds) in locating the mobile, D, can be expressed as follows:

$\displaystyle \overline{​{C}}$ = $\displaystyle \sum^{​{w}}_{​{i=1}}$( $\displaystyle \sum^{​{i}}_{​{j=1}}$) $\displaystyle \pi_{​{i}}^{}$, $\displaystyle \overline{​{D}}$ $\displaystyle \sum^{​{w}}_{​{i=1}}$( i x $\displaystyle \pi_{​{i}}^{}$).

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:


cic1c2c3c4c5
pi0.30.050.10.30.25


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


$ \overline{​{C}}$ = n1$ \pi_{​{1}}^{}$ + (n1 + n2)$ \pi_{​{2}}^{}$ = 3(0.3 + 0.05 + 0.1) + (3 + 2)(0.3 + 0.25) = 3 x 0.45 + 5 x 0.55 = 4.1

$ \overline{​{D}}$ = 1$ \pi_{​{1}}^{}$ +2$ \pi_{​{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, $ \overline{​{C}}$, and the average paging delay in locating the mobile, $ \overline{​{D}}$, are:


$ \overline{​{C}}$ = n1$ \pi_{​{1}}^{}$ + (n1 + n2)$ \pi_{​{2}}^{}$ = 2(0.3 + 0.3) + (3 + 2)(0.05 + 0.1 + 0.25) = 2 x 0.6 + 5 x 0.4 = 3.2

$ \overline{​{D}}$ = 1$ \pi_{​{1}}^{}$ +2$ \pi_{​{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 1$ \le$w$ \le$n$ \le$100. 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

Source

Seoul 2009-2010

题意:

手机在蜂窝网络中的定位是一个基本问题,假设蜂窝网络已经得知手机处于c1,c2,,,cn这些区域中的一个,最简单的方法是同时在这些区域中寻找手机,但这样做很浪费带宽,由于蜂窝网络中可以得知手机在这不同区域中的概率,因此一个折中的办法就是把这些区域分成w组,然后依次访问,求最小的访问区域数的期望值。比如,已知手机可能位于5个区域,概率分别是0.3 0.05 0.1 0.3 0.25,w=2,最优方法是分为{c1, c4} {c2, c3, c5} 则访问区域期望值:2*(0.3+0.3)+(3+2)*(0.05+0.1+0.25)=3.2



思路:

首先分析一下可以发现贪心规则,概率越大的放在前面,这样可以使最后的和最小。

所以先从大到小排一遍序,然后顺便求出概率前缀和sum,这样就可以用DP来求了

dp[i][j] 表示前i个区域分为j组访问取余的期望

则dp[i][j] = min{dp[k-1]j-1]+i*(sum[i]-sum[k-1])} j<=i



#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;

//#define WIN
#ifdef WIN
typedef __int64 LL;
#define iform "%I64d"
#define oform "%I64d\n"
#define oform1 "%I64d"
#else
typedef long long LL;
#define iform "%lld"
#define oform "%lld\n"
#define oform1 "%lld"
#endif

#define S64I(a) scanf(iform, &(a))
#define P64I(a) printf(oform, (a))
#define P64I1(a) printf(oform1, (a))
#define REP(i, n) for(int (i)=0; (i)<n; (i)++)
#define REP1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FOR(i, s, t) for(int (i)=(s); (i)<=(t); (i)++)

const int INF = 0x3f3f3f3f;
const double eps = 10e-9;
const double PI = (4.0*atan(1.0));

const int maxn = 100 + 20;
int A[maxn];
int sum[maxn];
int dp[maxn][maxn];

bool cmp(int a, int b) {
    return a > b;
}

int main() {
    int T;
    
    scanf("%d", &T);
    while(T--) {
        int n, w;
        scanf("%d%d", &n, &w);
        sum[0] = 0;
        for(int i=1; i<=n; i++) {
            scanf("%d", &A[i]);
        }
        sort(A+1, A+n+1, cmp);
        sum[0] = 0;
        for(int i=1; i<=n; i++) sum[i] = sum[i-1] + A[i];
        memset(dp, 0x3f, sizeof(dp));
        dp[0][0] = 0;
        for(int i=1; i<=n; i++) {
            for(int j=1; j<=w; j++) {
                for(int k=1; k<=i; k++) {
                    int t = dp[k-1][j-1] + i*(sum[i]-sum[k-1]);
                    dp[i][j] = min(dp[i][j], t);
                }
            }
        }
        printf("%.4lf\n", (double)dp[n][w]/sum[n]);
    }

    return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值