Throwing Dice LightOJ-1064

Source: Internet
Author: User
Tags gcd

Tag: code greater than Mon void lightoj type Test bic names

n Common cubic dice is thrown. What is the probability, the sum of all thrown dice are at least x?

Input

Input starts with an integer T (≤200), denoting the number of test cases.

Each test case contains the integers n (1≤n <) and x (0≤x <). The meanings of n and x is given in the problem statement.

Output

For each case, output the case number and the probability in ' p/q ' form where p and Q is Relat Ively Prime. If q equals 1 then print p only.

Sample Input

7

3 9

1 7

24 24

15 76

24 143

23 81

7 38

Sample Output

Case 1:20/27

Case 2:0

Case 3:1

Case 4:11703055/78364164096

Case 5:25/4738381338321616896

Case 6:1/2

Case 7:55/4665

Solution: Dp[I [j] represents the number of scenarios where I dice are thrown and are J.

So, dp[I [J]=dp[i] [j]+dp[I-1] [j-k] (1<=K<J)

1 #defineINF 1e82#include <cstdio>3#include <cstring>4#include <iostream>5#include <algorithm>6 using namespacestd;7typedefLong Longll;8 9 intn,x;Ten ll sum; Onell dp[ -][ Max]; A  - ll gcd (ll A,ll b) { -     returnb==0? A:GCD (b,a%b); the } -  - voidsolve () { -sum=1; +Memset (DP,0,sizeof(DP)); -dp[0][0]=1; +      for(intI=1; i<=n;i++){ Asum=sum*6; at          for(intj=1; j<=i*6; j + +) -              for(intk=1; k<=6; k++) -                 if(j>=k) dp[i][j]=dp[i][j]+dp[i-1][j-K]; Because Dp[0][0]=1, J must be greater than or equal to K, otherwise the value of Dp[i][j] cannot be updated -     } - } -  in intMain () -{intKase; toCin>>Kase; +      for(intt=1; t<=kase;t++){ -Cin>>n>>x; the solve (); *ll ans=0; $          for(inti=x;i<=n*6; i++) ans+=Dp[n][i];Panax Notoginsengll temp=gcd (Sum,ans); -         if(ans==0) printf ("Case %d:0\n", T); the         Else if(ans==sum) printf ("Case %d:1\n", T); +         Elseprintf"Case %d:%lld/%lld\n", t,ans/temp,sum/temp); A     } the}

Throwing Dice LightOJ-1064

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.