hdu-5816 Hearthstone (pressure dp+ probability expectation)

Source: Internet
Author: User
Tags greatest common divisor

Topic Links:

Hearthstone

Time limit:2000/1000 MS (java/others)

Memory limit:65536/65536 K (java/others)



Problem Descriptionhearthstone is a online collectible card game from Blizzard Entertainment. Strategies and luck is the most important factors in this game. When you suffer a desperate situation and your only hope depends on the top of the card deck, and you draw the ' only card t o Solve this dilemma. We call the "Shen Chou Gou" in Chinese.

Now is asked to calculate the probability to become a "Shen Chou Gou" to kill your enemy in this turn. To simplify this problem, we assume that there is only a kinds of cards, and you don ' t need to consider the cost of the Cards.
-a-card:if the card deck contains less than-cards, draw all the cards from the card deck; Otherwise, draw cards from the top of the card deck.
-b-card:deal X damage to your enemy.

Note that different b-cards could have different X values.
At the beginning, there is no cards in your hands. Your enemy have P hit Points (HP). The card deck has N a-cards and M b-cards. The card deck has been shuffled randomly. At the beginning of your turn, you draw a-card from the top of the the card deck. You can use any of the cards in your hands until to run out of it. Your task is to calculate the probability so you can win in this turn, i.e., can deal at least P damage to Your enemy.

Inputthe first line is the number of test cases T (t<=10).
Then come three positive integers P (p<=1000), N and M (N+M&LT;=20), representing the enemy ' s HP, the number of a-cards And the number of b-cards in the card deck, respectively. Next line come M integers representing X (0<x<=1000) values for the b-cards.

Outputfor each test case, output the probability as a reduced fraction (i.e., the greatest common divisor of the numerator and denominator is 1). If the answer is zero (one), you should output 0/1 (1/1) instead.

Sample Input23 1 21 23 5 101 1 1 1 1 1 1 1 1 1

Sample output1/346/273 Test Instructions: Give n Zhang a card, M Zhang B card, a card can take two. b card can be knocked out a[i] blood, ask to knock at least p point blood probability is how much; Idea: Dp[i] represents the number of scenarios in the I state, the answer is greater than or equal to P point state of the sum of the total number of schemes (N+M)! The ratio of the state of the word is the hand of a kind of card in this state whether the card can be held, the specific can see this link AC code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath>//#include <bits/stdc++.h> #include <stack> #include <map> using namespace std; #define for (i,j,n) for (int i=j;i<=n;i++) #define MST (SS,B) memset (ss,b,sizeof (ss)); typedef long Long LL;    Template<class t> void Read (t&num) {char CH; bool F=false; For (Ch=getchar (); ch< ' 0 ' | | Ch> ' 9 ';    f= ch== '-', Ch=getchar ()); for (num=0;    ch>= ' 0 ' &&ch<= ' 9 '; num=num*10+ch-' 0 ', Ch=getchar ()); F && (num=-num);}    int stk[70], tp;template<class t> inline void print (T p) {if (!p) {puts ("0"); return;}    while (p) stk[++ TP] = p%10, p/=10;    while (TP) Putchar (stk[tp--] + ' 0 '); Putchar (' \ n ');} Const LL Mod=1e9+7;const double Pi=acos ( -1.0); const int INF=1E9;CONST int N=1e5+10;const int maxn= (1&LT;&LT;20) +14;const Double eps=1e-12; LL dp[maxn],f[23];int num[maxn],p,n,m,a[30];inline void Init () {for (int i=0;i<maxn;i++) {        for (int j=0;j<20;j++) {if (i& (1<<j)) num[i]++;    }} f[0]=1; for (int i=1;i<=20;i++) f[i]=f[i-1]*i;}    int cal (int x) {int sum=0;    for (int i=0;i<m;i++) {if (x& (1<<i)) sum+=a[i]; } return sum;}    ll gcd (ll X,ll y) {if (y==0) return x; return gcd (y,x%y);}    int counter (int x) {int sum=0;    for (int i=0;i<m;i++) {if (x& (1<<i)) sum++; } return num[x]-2*sum+1;}    int main () {Init ();    int t;    Read (t);        while (t--) {MST (dp,0);        Read (P); Read (n); read (m);        for (i,0,m-1) read (A[i]);        LL ans=0;        int tot= (1<< (n+m))-1;        Dp[0]=1;            for (int i=0;i<=tot;i++) {if (!dp[i]) continue; if (i==tot| |            Counter (i) ==0) {if (Cal (i) >=p) ans=ans+dp[i]*f[n+m-num[i]]; } else {for (int j=0;j<n+m;j++) {if (i& (1&LT;&LT;J)) continue; Dp[i| (                1&LT;&LT;J)]+=dp[i];        }}} LL g=gcd (Ans,f[n+m]);    cout<<ans/g<< "/" <<f[n+m]/g<< "\ n"; } return 0;}

  

hdu-5816 Hearthstone (pressure dp+ probability expectation)

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.