UVA - 1456 Cellular Network

來源:互聯網
上載者:User

標籤:mod   方法   script   最小   .text   網路   str   tty   ack   

題目大意:

手機在蜂窩網路中的定位是一個基本問題。如果蜂窩網路已經得知手機處於c1, c2,…,cn這些地區中的一個。最簡單的方法是同一時候在這些地區中尋找手機。但這樣做非常浪費頻寬。

因為蜂窩網路中能夠得知手機在這不同地區中的機率。因此一個折中的方法就是把這些地區分成w組,然後依次訪問。比方。已知手機可能位於5個地區中,機率分別為0.3、0.05、0.1、0.3和0.25,w=2,則一種方法是先同一時候訪問{c1,c2,c3},再同一時候訪問{c4,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。

解題思路:

由公式能夠發現。為了讓總期望值最小,應該讓機率大的地區盡量放在前面去訪問。

所以先把全部機率從大到小排序一遍。然後分組時,就能夠取連續的一段分為一組了。

f[i][j]表示: 前i個,分成j組的最小期望值
f[i][j] = min{ f[k-1][j] + i*sum[k~i], 1<=k<=i}

#include <cstdio>#include <iostream>#include <algorithm>using namespace std;int main() {    int T;    scanf("%d", &T);    while (T--) {        int n, w;        double sum[110] = {0}, DP[110][110] = {0}, total = 0;        scanf("%d%d", &n, &w);        for (int i = 1; i <= n; i++) {            scanf("%lf", &sum[i]);            total += sum[i];        }        sort(sum + 1, sum + n + 1, greater<double>());        for (int i = 1; i <= n; i++)            sum[i] = sum[i] / total + sum[i-1];        for (int i = 1; i <= n; i++)  {            DP[i][0] = 0x3f3f3f3f;            for (int j = 1; j <= w; j++) {                DP[i][j] = 0x3f3f3f3f;                for (int k = 1; k <= i; k++)                    DP[i][j] = min(DP[i][j], DP[k-1][j-1] + i * (sum[i] - sum[k-1]));            }        }        printf("%.4lf\n", DP[n][w]);    }    return 0;}

UVA - 1456 Cellular Network

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.