Coursera University program design and algorithm special courses perfect coverage

Source: Internet
Author: User

#include <iostream>using namespacestd;/*int Wanmeifugai (int n) {if (n%2) {return 0;    } else if (n==2) {return 3;    }else if (n = = 0) return 1; else return (3*3) *wanmeifugai (n-4);}*///The following is a reference to the online program/*Ideas: Citation:http://m.blog.csdn.net/blog/njukingway/20451825First: F (n) = 3*f (n-2) + ... f (n) = 3*f (n-2) + 2*f (n-4) +....//just now our recursion is pushed in the smallest unit (3 blocks), but there are large units of small units (6, 9, 12 blocks, etc.) There are also connections F (n) =3*f (n-2) +2*f (n-4) + ... 2*f (0)//f (0) should be set to 1, so that the following n= n-2; Subtract and then simplify it. The connection problem can be found in the even-numbered interfaces further simplification may be f (n) =4*f (n-2)-F (n-4)*/intWanmeifugai (intN) {    if(n = =0)        return 1; Else if(n%2)        return 0; Else if(n = =2)//This is also a cutoff condition that must be written        return 3; Else        return 4*wanmeifugai (n2)-Wanmeifugai (n4);}intMain () {intN; CIN>>N;  while(N!=-1) {cout<<wanmeifugai (n) <<Endl; CIN>>N; }    return 0;}

Coursera University program design and algorithm special courses perfect coverage

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.