Have done a similar feeling of the problem, but there is no way to the pressure on the shape, can not find the connection between.
Test instructions: Give you a p,n Zhang out of nothing, M Zhang damage card. Draw a card and ask how much the probability of killing him is.
20 cards directly in the state, down the transfer if the number of leaves is greater than the number of out-of-the-way is the boundary, can not be updated. Because imagine a tree full of two, damage card is the leaf, nothing is inside. Just correspond to the problem of the licensing process.
Consider an answer as a sequence, the beginning of which the sequence has to win, then how to rank the freedom of the cards, and finally divided by the total number of OK.
It is my understanding that the two places on the internet are not very clear.
#include <cstdio>#include<cstring>#include<cmath>#include<vector>#include<algorithm>#include<iostream>#include<cstdlib>#include<string>#include<vector>#include<Set>using namespaceStd;typedefLong LongLL; LL fac[ A]; LL val[ A]; LL dp[1<< +];intMain () {fac[1]=fac[0]=1; for(LL i=2; i<= -; i++) Fac[i]=fac[i-1]*i; intT; scanf ("%d",&T); while(t--) {memset (DP,0,sizeof(DP)); LL p,n,m; scanf ("%i64d%i64d%i64d",&p,&n,&m); LL N=n+m; for(LL i=n;i<n;i++) scanf ("%i64d",&Val[i]); dp[0]=1; for(LL st=0;st< (1<<N); st++) { if(dp[st]==0)Continue; LL Dam=0, num_a=0, num_b=0; for(LL i=n;i<n;i++) { if(st& (1<<i)) dam+=val[i],num_b++; } if(dam>=p)Continue; for(LL i=0; i<n;i++) { if(st& (1<<i)) num_a++; } if(num_a+1<=num_b)Continue; for(LL i=0; i<n;i++) { if(st& (1<<i))Continue; Dp[st+(1<<i)]+=Dp[st]; }} LL ans=0, all=Fac[n]; for(LL st=0;st< (1<<N); st++) { if(dp[st]==0)Continue; LL Dam=0, num=0; for(LL i=n;i<n;i++) { if(st& (1<<i)) dam+=val[i],num++; } for(LL i=0; i<n;i++) { if(st& (1<<i)) num++; } if(dam>=p) {//cout<<dp[st]<< "" <<st<< "" <<fac[N-num]<<endl;ans+=dp[st]*fac[n-num]; }} LL e=__GCD (Ans,all); printf ("%i64d/%i64d\n", ans/e,all/e); } return 0;}
HDU 5816 Hearthstone