codeforces-261b Maxim and Restaurant

Source: Internet
Author: User


Title: given n number (n<=50,ai<=50), randomly disturbed, remember Si=a1+a2+a3...+ai, ask to meet the maximum value of si<=p I expectations. (P<=50)

(to the effect from

We know that the whole arrangement is actually equivalent to the probability of inserting a value into a sequence one by one.

So we can look at the problem this way:
? Now there are n number, n boxes, and so on the probability to put these numbers into the box, seeking Si<=p's max[i] expectations

We consider each box's contribution to the answer.

If the first box is saved, then its contribution is P (the probability of saving)

So we just have to calculate the probability that each box will be saved.

We also found that if the first box was preserved, then the 1~ (i-1) box must have been preserved.

Otherwise, the first box can not be preserved, in the original text:
Maxim doesn ' t let no other guest in the restaurant
Even if one of the following guests in the queue would has fit in the table.
Plays a key role

So we define F[I][J][K] to indicate that the number of the first I is randomly placed in the box
The probability that the sum of the number of the first J box is filled and the first J box is K

Then we have f[i][j][k] = f[i-1][j][k]* (1-(j/i)) + f[i-1][j-1][k-a[i]]* (j/i)

Then ans = sigma{f[n][i][j]} (1<=I<=N;0<=J<=P)

1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5typedefLong Longll;6InlinevoidReadint&x) {7x=0;CharChBOOLFlag =false;8      while(Ch=getchar (),ch<'!');if(ch = ='-') Ch=getchar (), flag =true;9      while(x=Ten*x+ch-'0', Ch=getchar (),ch>'!');if(flag) x=-x;Ten } OneInlineintCat_max (Const int&a,Const int&AMP;B) {returnA>b?a:b;} AInlineintCat_min (Const int&a,Const int&AMP;B) {returnA<b?a:b;} - Const intMAXN = the; - Doublef[2][MAXN][MAXN]; the intA[MAXN]; - intMain () { -     intn;read (n); -      for(intI=1; i<=n;++i) read (A[i]); +     intP;read (p); -f[0][0][0] =1.0; +      for(intI=1; i<=n;++i) { A          for(intj=0; j<=i;++j) { at              for(intk=0; k<=p;++k) { -                 if(A[i] > K) f[i&1][j][k] = f[(i-1) &1][j][k]* (I-J)/i; -                 Elsef[i&1][j][k] = f[(i-1) &1][j][k]* (I-J)/i + f[(i-1) &1][j-1][k-a[i]]*j/i; -             } -         } -     } in     DoubleAns =.0; -      for(intI=1; i<=n;++i) { to          for(intj=0; j<=p;++j) { +Ans + = f[n&1][i][j]; -         } the}printf ("%.10lf\n", ans); * GetChar (); GetChar (); $     return 0;Panax Notoginseng } -   

codeforces-261b Maxim and Restaurant

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: 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.