UVa 10759 Dice throwing: probability dp

Source: Internet
Author: User
Tags continue gcd time limit

10759-dice throwing

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=1700

N Common cubic dice are thrown. What is the probability this sum of all thrown dice are at least x?

Input

The input file contains several test cases. Each test case consists two integers n (1<=n<=24) and X (0<=x<150). The meanings of N and X are given in the problem statement. The Input is terminated by a case where n=0 and x=0. This case should is processed.

Output

For each line of input produce one line of output giving the requested probability as a proper fraction in lowest terms in The format shown in the sample output. All numbers appearing in output are representable in unsigned 64-bit integers. The last line of input contains two zeros and it should is processed.

Sample input Output for sample input

20/27

From the bottom up slowly add ~

F[i + 1][j + K] + = f[i][j];

Complete code:

/*0.015s*/#include <cstdio> typedef unsigned long long ull;  
      
Ull f[25][150];  
Ull gcd (ull A, ull b) {return B. gcd (b, a% B): A;  
    int main () {int I, j, K, N, X;  
    Ull ans, b, G;  
    for (i = 1; I <= 6; ++i) f[1][i] = 1;  
                for (i = 1; i < ++i) for (j = i; J <= 6 * i; ++j) for (k = 1; k <= 6; ++k)  
    F[i + 1][j + K] + = f[i][j];  
            while (scanf ("%d%d", &n, &x), N) {if (x > 6 * N) {puts ("0");  
        Continue  
            else if (x <= N) {puts ("1");  
        Continue  
        Ans = 0, b = 1;  
        for (i = x; I <= 6 * n; ++i) ans + f[n][i];  
        for (i = 0; i < n; ++i) b *= 6;  
        g = gcd (ans, b);  
    printf ("%llu/%llu\n", ans/g, b/g); }  
}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

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.