Links: Https://www.nowcoder.com/acm/contest/116/F
Source: Niu Ke Net
Title Description We know that there is a magical sort of order called monkeys, that is to write the numbers to be sorted on the card, and then let the monkeys throw the cards in the air, and so on when they fall to observe whether the cards are sorted from left to right (we do not think that the card will be stacked after the landing) if ordered to complete, Otherwise let the monkey throw again, until the card is orderly, then the problem comes, give you n cards, each card is written with a capital letter, ask the monkeys to throw these cards for the first time according to the dictionary order to complete the probability of how much?
Input Description:
The first line is an integer n (1<n<100) to give the monkey n cards, followed by a string of length n, representing the letters written on the cards.
Output Description:
The output line indicates the probability that the monkey will succeed on the first order (expressed as a fraction of 1 of the numerator).
Example 1 input
7SCIENCE
Output
1/1260
Test instructions: Chinese problem;
Idea: Start with C + + results have been 33.33 still think thinking wrong, behind only found that 100 factorial will explode to use large number, decisive open Java
Code:
import Java.math.biginteger;import Java.util.Scanner; Public classMain { Public Static voidMain (string[] args) {Scanner cin=NewScanner (System.inch); intN; BigInteger A, B; b=Biginteger.one; A=Biginteger.one; N=Cin.nextint (); int[] num=New int[ -]; String str; STR=Cin.next (); for(intI=0;i< -; i++) num[i]=0; for(intI=0; I<str.length (); i++) {Num[str.charat (i)-'A']++; //System.out.println (Num[i]);} BigInteger ans=Biginteger.one; for(inti =1; I <= N; i++) ans=ans.multiply (biginteger.valueof (i)); for(intI=0;i< -; i++) {BigInteger now=Biginteger.one; for(intj =1; J <= Num[i]; J + +) Now=now.multiply (Biginteger.valueof (j)); Ans=Ans.divide (now); } System. out. println ("1/"+ans);}}
Xinjiang University ACM-ICPC Program Design Competition May Month (synchronized)-The expectation of the sort of monkeys