Ultraviolet A 10759 Dice Throwing

Source: Internet
Author: User

UVA_10759

We may think of N shards as throwing in sequence, so that at most 6 ^ N states can be represented by long, it is easier for us to use DP to find the total number of States not greater than X, so that we can divide them after calculation.

#include<stdio.h>
#include<string.h>
int N, X;
long long int f[30][160];
long long int gcd(long long int x, long long int y)
{
return y == 0 ? x : gcd(y, x % y);
}
void solve()
{
int i, j, k, p;
long long int a, b, c;
memset(f, 0, sizeof(f));
for(j = 1; j <= 6; j ++)
for(k = j + 1; k <= X; k ++)
f[1][k] += 1;
for(i = 2; i <= N; i ++)
for(j = 1; j <= 6; j ++)
for(k = j + 2; k <= X; k ++)
f[i][k] += f[i - 1][k - j];
b = 1;
for(i = 1; i <= N; i ++)
b *= 6;
a = b - f[N][X];
c = gcd(b, a);
a /= c, b/= c;
if(a == 0)
printf("0\n");
else if(b == 1)
printf("1\n");
else
printf("%lld/%lld\n", a, b);
}
int main()
{
for(;;)
{
scanf("%d%d", &N, &X);
if(!N && !X)
break;
solve();
}
return 0;
}


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.