HUD 1465 is not one of the easy series

Source: Internet
Author: User

Original title Link: click here

Problem Solving Ideas:

Should belong to the topic of recursion.

Is that n letters are loaded with the wrong envelope ...

Let's say there are 7 envelopes: a~g

A

_ _ _ _ _ _ _

A

There are 7-1 things wrong with a, first choose a place B

A

B _ _ _ _ _ _

Start to put B, B can put a also can put other, if put a, is left n-2 of the arrangement,

If we put the other assumptions in C, that's the n-1 of the rest.

This can be summed up in the law:

f[n]= (n-1) * (f[n-1] + f[n-2]).

Source:

#include <iostream>#include<stdio.h>using namespacestd;Long Longa[ +]={0,0,1,2};intN;intMain () { for(intI=3; i<= +; i++) A[i]= (I-1) * (a[i-1]+a[i-2]);  while(cin>>N) cout<<a[n]<<Endl; return 0;}
View Code

HUD 1465 is not one of the easy series

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.