Fork me on GitHub

NYOJ题目872开会

--------------------------------------

每次的可能性公式如下:

AC代码:

 1 import java.util.Scanner;
 2 
 3 public class Main {
 4 
 5     public static void main(String[] args) {
 6         
 7         Scanner sc=new Scanner(System.in);
 8         
 9         while(sc.hasNextInt()){
10             
11             int s=sc.nextInt();
12             int n=sc.nextInt();
13             
14             while(n-->0){
15                 int a=sc.nextInt();
16                 System.out.print(c(s,a)+" ");
17                 s-=a;
18             }
19             System.out.println();
20         }
21     }
22     
23     public static long c(int n,int m){
24         long a=1;
25         for(int i=0;i<m;i++) a*=(n-i);
26         long b=1;
27         for(int i=2;i<=m;i++) b*=i;
28         return a/b;
29     }
30     
31 }

 

题目来源: http://acm.nyist.net/JudgeOnline/problem.php?pid=872

posted @ 2016-09-11 18:24  CC11001100  阅读(309)  评论(0编辑  收藏  举报