Algorithm: UVA 1456

Source: Internet
Author: User
Tags min

Meaning

(Excerpt from the LRJ Training Guide)

Mobile phone positioning in the cellular network is a fundamental problem. Assuming that the cellular network has known that the handset is in C1, C2,..., cn One of these areas, the easiest way is to find the phone in these areas at the same time. But doing so is a waste of bandwidth. Because the cellular network can know the cell phone in this different area of probability, so a compromise method is to divide these areas into the W group, and then access. For example, a known cell phone may be located in 5 areas, the probability of 0.3, 0.05, 0.1, 0.3 and 0.25,w=2, one method is to access the {C1,C2,C3} at the same time, and then access the {C4,C5}, the number of access areas of the mathematical expectation of 3* (0.3+0.05+0.1) + (3+2) * (0.3+0.25) = 4.1. Another method is to access {C1,C4} at the same time, then access {C2,C3,C5}, and the mathematical expectation for the number of access areas is 2x (0.3+0.3) + (3+2) x (0.05+0.1+0.25) = 3.2.

Ideas

The formula can be found that in order to minimize the total expected value, the probability of the region should be large as far as possible before the visit.

So start by sorting all the probabilities from big to small. Then when grouping, you can take a continuous paragraph into a group.

F[I][J] Represents: The first I, the minimum expected value of the J group

F[I][J] = min{F[k-1][j] + i*sum[k~i], 1<=k<=i}

Code

/**========================================== * is a solution for ACM/ICPC problem * * @source: uva-1456 Cellular Network * @type: Greedy + probability + dp * @author: Shuangde * @blog: blog.csdn.net/shuangde800 * @email: zengshuangde@gmail.com *== =========================================*/#include <iostream> #include <cstdio> #include <algorithm
    
> #include <vector> #include <queue> #include <cmath> #include <cstring> using namespace std;
typedef long long Int64;
const int INF = 0X3F3F3F3F;
    
Const double PI = ACOs (-1.0);
const int MAXN = 110;
int N, W;
int U[MAXN];
    
Double F[MAXN][MAXN], P[MAXN], SUM[MAXN]; int main () {int ncase; scanf ("%d", &ncase); while (ncase--) {scanf ("%d%d", &n, &w); int tot = 0; int i = 1; I <= N;
    
    
++i) {scanf ("%d", &u[i]); tot + = U[i];
    
Sort (u+1, U+1+n, greater<int> ());
    
for (int i = 1; I <= n; ++i) {p[i] = U[i]*1.0/tot; Sum[i] = Sum[i-1] + p[i];} for (int i = 1; I <= N; ++i) {f[i][0] = inf; for (int j = 1; J <= W. ++j) {F[i][j] = INF; for (int k = 1; k <= i; ++k)//K~i is divided into a group//HTTP://WW
w.bianceng.cn F[i][j] = min (F[i][j], f[k-1][j-1] + i* (sum[i]-sum[k-1));
    
} printf ("%.4f\n", F[n][w]);
return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.