Xinjiang University ACM-ICPC Program Design Competition May Month (synchronized)-The expectation of the sort of monkeys

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.