HDU 2048 God, God, and the heavens (dp+ + combinatorial math)

Source: Internet
Author: User

God, God, and the heavens.Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 32673 Accepted Submission (s): 13367

problem DescriptionHDU 2006 ' ACM Contest's Awards gala begins!
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?!

InputThe first line of the 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.

Outputfor each test instance, output the percentage that this occurs, the output of each instance is a row, the result is two decimal places (rounded), and the format is referenced by the sample output.

Sample Input
12

Sample Output
50%
 
AuthorLCY
SourceRecursive Solution topic exercise (for beginner)
troubleshooting: Wrong sort. Mismatch formula: dp[i]= (i-1) * (Dp[i-1]+dp[i-2])
AC Code:
#include <iostream> #include <cstdlib> #include <cstdio> #include <cmath> #include <cstring > #include <string> #include <cstdlib> #include <iomanip> #include <algorithm> #include < Time.h>typedef Long long ll;using namespace Std;int main () {    int i,t,n;double a[20];scanf ("%d", &t); a[1]=0;a[ 2]=1;for (i=3;i<=20;i++) {   a[i]= (i-1) * (A[i-1]+a[i-2]);  Wrong sort}while (t--) {scanf ("%d", &n); for (i=1;i<=n;i++) {  


 

HDU 2048 god, God, and the heavens (dp+ + combinatorial math)

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.