c-throwing Dice
Time limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld &%llu
Lightoj 1064 Udebug
Description
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 Relatively 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/46656
The game did not read the title, this is a simple probability DP, the first line is the case number T, and then N, M is the probability that N dice throw at least m.
DP[I][J] Represents the I dice, throw the J-type number
Dp[i+1][j+k]=sigma (Dp[i][j]) (1<=k<=6)
1#include <cstdio>2#include <iostream>3#include <cstring>4 using namespacestd;5 6__int64 dp[ -][155];7 8 __int64 gcd (__int64 x,__int64 y)9 {Ten returnY?GCD (y,x%y): x; One } A - intMain () - { the __int64 up,down,g; - intt,n,x,i,j,k; - - for(i=1; i<=6; i++)//a dice +dp[1][i]=1; - for(i=1;i< -; i++)//Dice + { A for(j=i;j<=6*i;j++)//all the points in this dice at { - for(k=1; k<=6; k++)//the point of the next dice -dp[i+1][j+k]+=Dp[i][j]; - } - } - inscanf"%d",&T); - for(intcas=1; cas<=t;cas++) to { +scanf"%d%d",&n,&x); - if(x>n*6) the { *printf"Case %d:0\n", CAs); $ Continue;Panax Notoginseng } - if(x<=N) the { +printf"Case %d:1\n", CAs); A Continue; the } +up=0, down=1; - for(i=x;i<=n*6; i++) $up+=Dp[n][i]; $ for(j=0; j<n;j++) down*=6;//all the dice could be the case -g=gcd (up,down); -printf"Case %d:%i64d/%i64d\n", cas,up/g,down/g); the } - return 0;Wuyi}
View Code
Throwing Dice (probabilistic DP)