P1291 [SHOI2002] Pepsi World Cup tour
Set $f (n,k) $ for a total of n names, the remaining k names are not collected, but also the average number of drinks to be purchased
Then there are:
$f (n,k) =\frac{n-k}{n}*f (n,k) + \frac{k}{n}*f (n,k+1) +1$
To move items, you get:
$f (n,k) =f (n,k+1) +\frac{n}{k}$
Depending on the recursion, you get:
$f (n,0) =n\sum_{k=1}^{n}\frac{1}{k}$
Blue after GCD engage numerator
Note the output
End.
#include <iostream>#include<cstdio>#include<cstring>#defineRe Registerusing namespaceStd;typedefLong Longll;ll p,q=1, G;intn;ll gcd (ll a,ll b) {returnB?GCD (b,a%b): A;}intwid (ll x) {//Calculation of digitsintres=0; for(; x;x/=Ten)++Res; returnRes;}intMain () {scanf ("%d",&N); for(ReintI=1; i<=n;++i) {P=p*i+q*n; q*=i; G=gcd (P,Q); P/=g,q/=G; }g=p/q,p%=P; in a variety of situationsif(!p) printf ("%lld", G); Else{ for(ReintI=wid (g); i>=1; i.) Putchar (' '); printf ("%lld\n", p); if(g) printf ("%lld", G); for(ReintI=wid (q); i>=1; i.) Putchar ('-'); Putchar ('\ n'); for(ReintI=wid (g); i>=1; i.) Putchar (' '); printf ("%lld", q); }return 0;}
P1291 [SHOI2002] Pepsi World Cup tour (probability)