-
Notifications
You must be signed in to change notification settings - Fork 2
/
1064 - Throwing Dice.cpp
53 lines (52 loc) · 1.13 KB
/
1064 - Throwing Dice.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<bits/stdc++.h>
using namespace std;
#define ll long long
/// ///////////////////////////////////
/// dp(i, j) : Probability of sum at least X with i throws and previous sum of j.
/// ///////////////////////////////////
ll dp[26][152];
int lim;
ll fun(int dice, int sum)
{
if(dice==0 )
return (sum>=lim);
ll& ret = dp[dice][sum];
if(ret!=-1)
return ret;
ret = 0;
for(int i=1; i<=6; i++)
{
ret+=fun(dice-1, sum+i);
}
return ret;
}
int main()
{
int tc,n,x,cs=1;
scanf("%d",&tc);
while(tc--)
{
scanf("%d%d",&n,&x);
lim = 0;
memset(dp, -1, sizeof dp);
ll q = fun(n,0);
lim = x;
memset(dp, -1, sizeof dp);
ll p = fun(n,0);
//cout<<p<<" "<<q<<endl;
printf("Case %d: ",cs++);
if(p<=0)
printf("0\n");
else
{
ll gc = __gcd(p,q);
p/=gc;
q/=gc;
if(q==1)
printf("%lld\n",p);
else
printf("%lld/%lld\n",p,q);
}
}
return 0;
}