lightoj1064 - Throwing Dice【dp打表】
来源:互联网 发布:网络文档 编辑:程序博客网 时间:2024/06/05 05:48
1064 - Throwing Dice
PDF (English)StatisticsForum
Time Limit: 2 second(s)Memory Limit: 32 MB
n common cubic dice are thrown. What is the probability that the sum of all thrown dice is at least x?
Input
Input starts with an integer T (≤ 200), denoting the number of test cases.
Each test case contains two integers n (1 ≤ n < 25) and x (0 ≤ x < 150). The meanings of n and x are given in the problem statement.
Output
For each case, output the case number and the probability in 'p/q' form where p and q are relatively prime. If q equals 1 then print p only.
Sample Input
Output for Sample Input
7
3 9
1 7
24 24
15 76
24 143
23 81
7 38
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
/* ***********************************************Author : rycCreated Time : 2016-08-25 ThursdayFile Name : E:\acm\LightOJ\106.cppLanguage : c++Copyright 2016 ryc All Rights Reserved************************************************ */#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>using namespace std;typedef long long LL;typedef pair<int,int>pii;const int maxn=10010;LL dp[30][155];int n,m;LL gcd(LL a,LL b){ return b==0?a:gcd(b,a%b);}void Find(){ dp[0][0]=1ll; for(int i=1;i<=25;++i){ for(int j=1;j<=150;++j){ for(int k=1;k<=6&&j-k>=0;++k){ dp[i][j]+=dp[i-1][j-k]; } } }}int main(){ Find(); int t,T=1;cin>>t; while(t--){ scanf("%d%d",&n,&m); LL ans=0,sum=1ll; for(int i=n;i<m;++i){ ans+=dp[n][i]; } for(int i=1;i<=n;++i){ sum*=6ll; }ans=sum-ans; printf("Case %d: ",T++); if(ans==0){ printf("0\n"); } else { LL g=gcd(ans,sum); if(sum/g==1){ printf("%lld\n",ans/g); } else { printf("%lld/%lld\n",ans/g,sum/g); } } } return 0;}
1 0
- lightoj1064 - Throwing Dice【dp打表】
- LIGHT OJ 1064 - Throwing Dice 【dp数塔+打表】
- 【LightOJ】1064 - Throwing Dice(dp打表)
- LightOJ 1064 Throwing Dice (DP)
- uva 10759 - Dice Throwing(dp)
- 【LightOJ 1064 】Throwing Dice + dp
- lightoj - 1064 - Throwing Dice - dp / 概率dp
- UVa 10759 Dice Throwing (概率DP)
- UVA 10759 Dice Throwing(dp 概率)
- Light oj 1064 Throwing Dice (概率dp)
- UVA10759 - Dice Throwing(dp+gcd)
- LightOJ 1064 Throwing Dice 概率DP
- LightOJ 1064 - Throwing Dice (dp)
- LightOJ 1064 - Throwing Dice(概率DP)
- Light OJ 1064 Throwing Dice(简单DP)
- LightOj 1064 Throwing Dice(概率dp)
- lightoj 1064 - Throwing Dice 简单DP
- Dice Throwing
- 1014 福尔摩斯的约会
- POJ 2109
- 李笑来 -把时间当作朋友
- 上拉XML
- Convert Sorted List to Binary Search Tree
- lightoj1064 - Throwing Dice【dp打表】
- String 和StringBuffer ?
- HTML5 文字变化和排版技巧
- java判断整数和浮点数
- 分布式系统协调 ZooKeeper
- B/S与C/S概念
- 菜单点击弹出动画 ViewpropertyAnimator
- C#高级编程-事务和网络
- Android屏幕适配 超级解决方案percent-support-lib