⑨ to write.

Source: Internet
Author: User

"Title description"

One day, Qi Cirno wrote n letters to be loaded into N envelopes, but all loaded wrong ... Now you want to know how many kinds of possibilities are wrong.

"Input description"
Number of letters and envelopes N.

"Output description"
The number of possibilities to mount the error.

"Sample Input"
Input Example 1

2

Input Example 2

4

"Sample Output"
Output Example 1

1

Output Example 2

9

"Data range and Tips"
1≤n≤100

source code: #include<cstdio>intn,f[101];intMain () {scanf ("%d",&N); f[1]=0; f[2]=1;  for(intA=3; a<=n;a++) F[a]= (A-1) * (f[a-1]+f[a-2]);//the wrong-row formula is applied. printf"%d", F[n]);//the subject should also use high-precision algorithms, but this is ignored.     return 0;}/*Number theory-"wrong formula": f[n]= (n-1) * (F[n-1]+f[n-2]) Step 1: Place nth element in any position, e.g. position K (except position N).    Step 2: Placing the K element is nothing more than the following two possible: (1) placed in position N: Then the remaining (n-2) elements have an F (n-2) method of placement. (2) Do not place in position N: the remaining (n-2) elements have an F (n-1) Placement method. */

⑨ to write.

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.