[UVA][JAVA][dp] 10238 - Throw the Dice@Morris' Blog|PChome Online 人新台
2012-10-29 07:17:40| 人1,172| 回0 | 上一篇 | 下一篇
<-- start of blogbody -->

[UVA][JAVA][dp] 10238 - Throw the Dice

0 收藏 0 0 站台

Problem C
Throw the Dice!

Input: standard input
Output: standard output
Time Limit: 30 seconds
Memory Limit: 32 MB

 

In the pictures below, you can see several types of Dices. It is very easy to assume that they are used in many different types of games. In this problem, the face of the dices will be like those on the first figure, that means each will have some dots it each face, which will indicate the value of that particular face. But the looks of the dices will be like those on the second figure, that means each dice may have 2, 3, 4, 5 up to 50 different faces. A dice with p faces have face values 1, 2, 3 … p. When a dice is thrown all the faces are equally likely to come on top. For example an ordinary dice in figure-1 has face values 1, 2, 3, 4, 5, 6 and the probability that face with value 1 will be on top is 1/6. The same is the probability for the other faces coming on top.

 

Figure 1: Two conventional dices Figure 2: Dices of different shape

 

The situation becomes complicated when you throw a dice more than once dice. For example when you throw a dice twice, for any arbitrary incident the summation of the top two faces can be within the range (inclusive) 2...12. But their probability is not equally likely or 1/12. The probability that the sum will be two is 1/36, but the probability that some will be three is 2/36 and so on. Given the description of a dice throw, that’s how many faces it have, how many throws will be made and value for the sum, you will have to find the probability of obtaining that sum.

 

Input

The input will contain several lines of input. Each line contains three integers F (The number of faces of the dice thrown, 1<=F<=50), N (The number of throws and 0<=N<=50) and S (The summation value for which you to find out the probability, 0<S<=4000).

 

Output

For each line of input you will have to produce one line of output which will be of the form a/b (Here b = FN). Here a/b means the probability value. Note that we don’t need thefloating point value of probability.

 

Sample Input
6 2 2
6 2 3
6 3 10

 

Sample Output
1/36
2/36
27/216



import java.math.BigInteger;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        while(cin.hasNext()) {
            int F, N, S;
            F = cin.nextInt();
            N = cin.nextInt();
            S = cin.nextInt();
            if(S < N || S > N*F)
                System.out.print("0");
            else {
                BigInteger[][] dp = new BigInteger[N+1][N*F+1];
                dp[0][0] = BigInteger.valueOf(1);
                for(int i = 1; i <= N; i++) {
                    for(int j = i; j <= i*F; j++) {
                        dp[i][j] = BigInteger.valueOf(0);
                        for(int k = 1; k <= F; k++) {
                            if(j-k >= 0 && j-k >= i-1 && j-k <= (i-1)*F) {
                                dp[i][j] = dp[i][j].add(dp[i-1][j-k]);
                            }
                        }
                    }
                }
                System.out.print(dp[N][S]);
            }
            BigInteger den = BigInteger.valueOf(F).pow(N);
            System.out.println("/" + den);            
        }
    }
}

台: Morris
人(1,172) | 回(0)| 推 (0)| 收藏 (0)|
全站分: 不分 | 人分: UVA |
此分下一篇:[UVA] 10895 - Matrix Transpose
此分上一篇:[UVA][dp] 542 - France '98

是 (若未登入"人新台"看不到回覆唷!)
* 入:
入片中算式的果(可能0) 
(有*必填)
TOP
全文
ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86