HDU 5816 Hearthstone

Source: Internet
Author: User

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&LT;&LT;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&LT;&LT;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

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: info-contact@alibabacloud.com 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.