UVA live 4731////state very well think://D (I,J) represents the minimum value of the mathematical expectation obtained by the first I network divided into J Group//Transfer equation://d (i,j) = min (d (k,j-1) +cost);//cost is the condition given by the topic. (K+1...I) segment Probability and * i;////NOTE://1) The probability of a large network in the front, so in the back, the large probability of appearing in//behind the opportunity will be small. Because each probability will be at least once, so the first big//can try to reduce the back of the big. 2) when initializing only D (0,0) is 0.0, the other is the INF, because any one is not 0 i//can not have D (i,0) this situation appears;//sentiment://Overall, is not very difficult, as long as the title meaning to understand the line, has been tangled/ This formula is how to prove, at last I was too stupid, only according to the formula of the topic//directly it, if someone can answer my doubts, $2.56 boy hands, and extend//most sincere thanks to # include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits># Include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring > #include <ctime> #include <deque> #include <functional> #include <iostream> #include < list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack > #include <vector> #define CEIL (a B) (((a) + (b)-1)/(b)) #define Endl ' \ n ' #define GCD __gcd#define highbit (x) (1ull<< (63-__builtin_clzll (x))) #define Popcount __builtin_popcountlltypedef Long Long ll;using namespace Std;const int MOD = 1000000007;const long Double PI = ACOs ( -1.L); int n,w;const int MAXN = 180;double D[maxn][max N];bool vis[maxn][maxn];int X[MAXN];d ouble s[maxn];bool cmp (int x,int y) {return x>y;} Double dp (int num,int WI) {if (Vis[num][wi]) return D[NUM][WI];VIS[NUM][WI] = 1;if (wi==0 | | num = = 0) return d[num][wi];for (int i=0;i<=num;i++) D[num][wi] = min (D[NUM][WI],DP (i,wi-1) + (s[num]-s[i]) * num); return D[NUM][WI];} void print () {for (int. i=1;i<=n;i++) {for (int j=1;j<=n;j++) {cout << d[i][j] << "";} cout << Endl;}} void Prin () {for (int i=1;i<=n;i++) cout << s[i] << ""; cout << Endl;} void Init () {scanf ("%d%d", &n,&w);d ouble sum = 0.0;for (int i=1;i<=n;i++) {scanf ("%d", &x[i]), sum +=x[i];} Sort (x+1,x+n+1,cmp); S[0] = 0.0;for (int i=1;i<=n;i++) {S[i] = s[i-1] + x[i]/sum;} Prin (); memset (vis,0,sizeof (VIS));T i=0;i<=n;i++) for (int j=0;j<=n;j++) {D[i][j] = 999999999;} d[0][0]=0.0;printf ("%.4lf\n", DP (N,W));//print ();//puts ("");} int main () {int T;//freopen ("1.txt", "R", stdin), scanf ("%d", &t), while (t--) {init ();} return 0;}
UVA Live 4731 Cellular Network linear DP