0
点赞
收藏
分享

微信扫一扫

HDOJ1570 A C(打表)


A C


Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5704    Accepted Submission(s): 3711


Problem Description


Are you excited when you see the title "AC" ? If the answer is YES , AC it ;


You must learn these two combination formulas in the school . If you have forgotten it , see the picture.



HDOJ1570 A C(打表)_HDU




Now I will give you n and m , and your task is to calculate the answer .


 



Input


In the first line , there is a integer T indicates the number of test cases.
Then T cases follows in the T lines.
Each case contains a character 'A' or 'C', two integers represent n and m. (1<=n,m<=10)


 



Output


For each case , if the character is 'A' , calculate A(m,n),and if the character is 'C' , calculate C(m,n).
And print the answer in a single line.


 



Sample Input


2 A 10 10 C 4 2


 



Sample Output


3628800 6


根据题目给出的公式可以知道都需要1~10的阶乘,可以打表,根据公式计算就OK


import java.util.Scanner;

public class Main{
private static Scanner scanner;
private static long arr[];
public static void main(String[] args) {
dabiao();
scanner = new Scanner(System.in);
int cases = scanner.nextInt();
while(cases-->0){
String string = scanner.next();
int n = scanner.nextInt();
int m = scanner.nextInt();
if(string.equals("A")){
System.out.println(arr[n]/arr[n-m]);
}else {
System.out.println(arr[n]/(arr[m]*arr[n-m]));
}
}
}
private static void dabiao() {
arr = new long[11];
arr[0] = 1;
arr[1] = 1;
for (int i = 2; i < arr.length; i++) {
arr[i] = arr[i-1]*i;
}
}
}



举报

相关推荐

0 条评论