描述:其实是个dp题,然后再计算两者的最大公约数化成最简
#include <cstdio>
#include <cstring>
int n,m,p[25];
unsigned long long v,sum,dp[30][150];
unsigned long long gcd(unsigned long long a,unsigned long long b)
{
if(a%b==0) return b;
else return gcd(b,a%b);
}
int main()
{
// freopen("in.txt","r",stdin);
while(scanf("%d%d",&n,&m)!=EOF)
{
if(!n&&!m) break;
int pos=n;
if(pos>=m) printf("1\n");
else if(n*6<m) printf("0\n");
else
{
v=1,sum=0;
for(int i=0; i<n; ++i) v=v*6;
memset(dp,0,sizeof(dp));
for(int i=0; i<=6; ++i) dp[0][i]=1;
for(int i=0; i<n-1; ++i)
for(int j=1; j<=(i+1)*6; ++j)
for(int k=1; k<=6; ++k)
dp[i+1][j+k]+=dp[i][j];
for(int i=m; i<=n*6; ++i) sum=sum+dp[n-1][i];
unsigned long long c=gcd(v,sum);
printf("%llu/%llu\n",sum/c,v/c);
}
}
return 0;
}
10759 - Dice Throwing
最新推荐文章于 2018-06-19 13:28:50 发布