zoj 3344 //组合数学那种的DP

 
 
 
 
import java.io.*;
import java.math.*;
import java.util.*;
/**
 *
 * @author acm
 */
public class Main
{
    public static void main(String[] args) 
    {
        Scanner cin = new Scanner(System.in);
        BigInteger dp[][] = new BigInteger[51][51];
        BigInteger d[] = new BigInteger[51];
        int i, j;
        //dp[i][j] = dp[i-1][j] * (i-1) + dp[i-1][j-1]
        for(i = 1; i <= 50; i++)
        {
            dp[i][0] = BigInteger.valueOf(0);
            dp[i][i] = BigInteger.valueOf(1);
            for(j = 1; j < i; j++)
            {
                dp[i][j] = dp[i-1][j].multiply(BigInteger.valueOf(i-1));
                dp[i][j] = dp[i][j].add(dp[i-1][j-1]);
            }
        }

        d[0] = BigInteger.valueOf(1);
        for(i = 1; i <= 50; i++)  d[i] = d[i-1] .multiply(BigInteger.valueOf(i));

        while(cin.hasNextInt())
        {
            int n, k;
            BigInteger sum, gcd;
            n = cin.nextInt();
            k = cin.nextInt();
            sum = BigInteger.valueOf(0);
            for(i = 1; i <= k; i+=2)  sum = sum.add(dp[n][i]);
            gcd = sum.gcd(d[n]);
            System.out.println(sum.divide(gcd)+"/"+d[n].divide(gcd));
        }
    }

}

你可能感兴趣的:(zoj 3344 //组合数学那种的DP)