Buy the Tickets

 1 //错排公式:
 2 import java.util.*;
 3 import java.math.*;
 4 import java.lang.*;
 5 import java.text.*;
 6 import java.io.*;
 7 class Main
 8 {
 9     public static void main(String[] args) 
10     {
11         int m,n,i,sum=0;
12         BigInteger a[]=new BigInteger[210],des=null;
13         a[1]=BigInteger.valueOf(1);
14         Scanner cin=new Scanner(System.in);
15         while(true)
16         {
17             for(i=2;i<210;i++)
18             {
19                 a[i]=a[i-1].multiply(new BigInteger(i+""));
20             }
21             sum++;
22             m=cin.nextInt();
23             n=cin.nextInt();
24             if(m==0&&n==0)break;
25             if(m<n)
26             {
27                 System.out.println("Test #"+sum+":");
28                 System.out.println("0");
29                 continue;
30             }
31             des=a[m+n].multiply(new BigInteger(""+(m-n+1))).divide(new BigInteger(""+(m+1)));
32             System.out.println("Test #"+sum+":");
33             System.out.println(des);
34         }
35     }
36 }

//里面还有一点点的排列组合思想

posted @ 2012-08-22 12:32  疼痛落在指尖  阅读(250)  评论(0编辑  收藏  举报