飞花的糖果
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
一日,飞花壕大手一挥,买了N个的两两不相同糖果,他想要拿出M个糖果送给他心仪的程序媛,他有多少种可以选择的方案?
例如,飞花壕有4块糖果,分别为①、②、③、④。他要选出3块送给他心仪的程序媛,他有四种选择,分别是①、②、③, ①、②、④, ①、③、④, ②、③、④ 这四种选择。
Input
多组输入。对于每组输入,有两个整数N、M(1 <= N、M <= 10),分表代表有N个糖果,要选择拿出M个送给他心仪的程序媛。
Output
输出为一个整数,代表飞花壕可以做出的选择的方案数。
Sample Input
4 3
5 2
Sample Output
4
10
import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
int x,y;
while(cin.hasNextLine())
{
x = cin.nextInt();
y = cin.nextInt();
System.out.println(get(x,y));
}
cin.close();
}
static int get(int x,int y)
{
int i,j,sum;
sum = 1;
for(i=1,j=x;i<=y;i++,j--)
{
sum *= j;
sum /= i;
}
return sum;
}
}