#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