Test instructions: There are $k$ kinds of apples and $n$ boxes, each box has some apples, first of all, the probability of selecting the $n$ box to form a set of non-empty empty, and then choose one randomly from the selected apples, ask each apple is selected probability is how much
Set the box $i$ have $cnt_{i,j}$ $j$ apples, the total number of apples in box $i$ $siz_i=\sum\limits_{j=1}^kcnt_{i,j}$, total apples $sum=\sum\limits_{i=1}^nsiz_i$
Since the selection of non-empty-empty set, each box of apples is the same probability of being selected, so first consider the box, set $f_{i,j}$ for the first $i$ box to choose $j$ the number of apples (only one box of the choice), then $f_{i,j}=f_{i-1,j}+f_{i-1, j-siz_i}$
Then set $g_{i,j}$ to choose the number of $j$ apples in all the boxes that are not $i$, then $g_{i,j}=f_{n,j}-g_{i,j-siz_i}$
#include <stdio.h> #include <vector> #include <string> #include <string.h>using namespace std; typedef double DU;TYPEDEF Long Long ll;ll f[500010],g[500010];int cnt[60][60],siz[60],sum;class randomapple{public: Vector<du>theprobability (vector<string>hun,vector<string>ten,vector<string>one) {int n,k , I,j;du t;n=hun.size (); K=hun[0].length (); for (i=0;i<n;i++) {for (j=0;j<k;j++) {cnt[i][j]= (hun[i][j]-' 0 ') *100+ (ten[i][j]-' 0 ') *10+one[i][j]-' 0 '; siz[i]+=cnt[i][j];} Sum+=siz[i];} Vector<du>res (k,0); F[0]=1;for (i=0;i<n;i++) {for (j=sum;j>=siz[i];j--) f[j]+=f[j-siz[i]];} for (i=0;i<n;i++) {memset (g,0,sizeof (g)); T=0;for (j=0;j<=sum;j++) {g[j]=f[j]-(j>=siz[i]?g[j-siz[i]]:0); if (j+siz[i]<=sum) t+=g[j]/(du) ((1ll<<n)-1)/(DU) (J+siz[i]);} for (j=0;j<k;j++) res[j]+=t*cnt[i][j];} Return res;}};/ *int Main () {randomapple Cl;vector<string>a,b,c;vector<du>res;char s[60];for (scanf ("%s", s); s[0]!= '-'; scanf ("%s", s)) A.push_back (s); for (scanf ("%s", s);s[0]!= '-'; scanf ("%s", s)) B.push_back (s); for (scanf ("%s", s); s[0]!= '-'; scanf ("%s", s) c.push_back (s); res= Cl.theprobability (A,b,c); for (du T:res) printf ("%.9lf", t);} */
[Srm478]randomapple