Uvalive 4731 Cellular Network

Source: Internet
Author: User
Tags define local

Analysis:

A state is a set of ordered collections that do not intersect and are set to all regions. It is obvious that enumerating the elements of a collection is not bearable,

Write the desired formula, you will find a greedy, when the size of each set is determined, the probability of a large priority access is optimal. It's easy to prove and intuitive.

So first you sort from big to small. The definition state F[i][j] represents the minimum expectation of the group I, starting with J.

Transfer is enumeration divided by K, then there is f[i][j] = min{f[i-1][k]+ (k-j) * (U[n]-u[j-1])},k>j

Boundary F[1][j] = (n-j+1) * (U[n]-u[j-1])

#include <bits/stdc++.h>using namespacestd;Const intMAXN = 1e4+4;intU[MAXN];intf[101][MAXN];Const intINF =0x3f3f3f3f;//#define LOCALintMain () {#ifdef LOCAL freopen ("In.txt","R", stdin);#endif    intT Cin>>u;  while(t--){        intN,w; scanf"%d%d",&n,&W);  for(inti =1; I <= N; i++) scanf ("%d". UIi); Sort (U+1. UI1+n,greater<int>());  for(inti =1; I <= N; i++) U[i] + = u[i-1];  for(intj = N; J >0; j--) {f[1][J] = (n-j+1) * (u[n]-u[j-1]); }         for(inti =2; I <= W; i++){             for(intj =1; J <= N; J + +) {F[i][j]=INF;  for(intK = j+1; K <= N; k++) {F[i][j]= Min (f[i-1][k]+ (K-J) * (u[n]-u[j-1]), f[i][j]); }}} printf ("%.4lf\n", f[w][1]/(Double) u[n]); }    return 0;}

Uvalive 4731 Cellular Network

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.