God, God, and Jesus Christ, recursion.

Source: Internet
Author: User

God, God, and Providence time Limit:2000/1000ms (Java/other) Memory limit:65536/32768k (Java/other) total submission (s): Accept Ed Submission (s): 32font:times New Roman | Verdana | Georgiafont Size:←→problem descriptionhdu 2006 ' ACM Contest Awards Gala Grand start!
In order to enliven the atmosphere, organizers held a special, prize-rich lottery, the specific requirements of this activity is:

First, all participants in the party put a note with their name in the lottery box;
Then, after all the notes are added, each person takes a note from the box;
Finally, if the note is written on its own name, then "Congratulations, the jackpot!" ”

You can imagine the atmosphere at that time, after all, the winner of the prize is everyone's dream twins signature photo! However, just as all the comedy attempts to design often end in tragedy, no one has won the lottery in the end!

My God, God, and the heavens, how could this be?

But let's not get excited, now that's the problem, can you calculate the probability of this happening?

Not counting? Do you also want to end with a tragedy?! The first line of input data is an integer c, representing the number of test instances, followed by the C row of data, each line containing an integer n (1<n<=20), representing the number of participants in the lottery.

Output for each test instance, export the percentage that this occurs, the output of each instance is a row, and the result retains two decimal places (rounded), in the exact format, refer to sample output.

Sample Input
12
Sample Output
50%
Test instructions is the number of people who draw the lottery, draw their own names to win the lottery, calculate the probability of no one person award
You can use the wrong row + recursion
Analysis: Put the nth element in the first position, such as K, there is a n-1, and this one, you can put the K position of the element in the n position, as long as the calculation of n-2 in the tower, that is f (n-2)
The k position can also be placed in another n-1 random position, that is F (n-1)
Get recursion f (n) = (n-1) (f (n-2) +f (n-1))
There are n! possible ways to take the total.
So just a little bit.
1#include <bits/stdc++.h>2 using namespacestd;3 Doublea[ +];4 intMain ()5 {6     intN;7a[1]=0; a[2]=1;8      for(intI=3; i<= -; i++)9     {Tena[i]= (I-1) * (a[i-1]+a[i-2]); One     } A      while(~SCANF ("%d",&N)) -     { -         inttemp; the          for(intI=0; i<n;i++) -         { -scanf"%d",&temp); -             Long Longsum=1; +              for(intj=1; j<=temp;j++) -             { +sum*=J; A             } at             Doubleb=100.0*a[temp]/sum; -printf"%.2f%%\n", b); -         } -     } -     return 0; -}

God, God, and Jesus Christ, recursion.

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.