Test instructions: slightly.
Analysis: First of all assume that the former n-2 has been put, then put Nth, first consider what n-1 put, then there are two situations.
If the n-1 is the same as the 1th, then the nth can be placed on the basis of N-2 2, that is 2 * f (n-2), that is, because N-1 and 1th, as the same,
So there are two types of nth (not the same as the 1th kind). So what if the first n-1 and the 1th one? Then the nth is the same as the first n-1, there is no choice but to put one.
The code is as follows:
#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <cstdio> #include <string> #include < cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include < queue> #include <algorithm> #include <vector> #include <map> #include <cctype>using namespace STD; typedef long Long Ll;typedef pair<int, int> p;const int inf = 0x3f3f3f3f;const double inf = 0x3f3f3f3 F3f3f3f;const double eps = 1e-8;const int maxn = 1e4 + 5;const int mod = 1e9 + 7;const int dr[] = {0, 0,-1, 1};const int Dc[] = {-1, 1, 0, 0};int N, m;inline bool is_in (int r, int c) {return R >= 0 && r < n && C >= 0 && C < m;} LL ans[55];void init () {ans[1] = 3; ANS[2] = ans[3] = 6; for (int i = 4; I <=; ++i) ans[i] = Ans[i-1] + ans[i-2] * 2LL;} LL f (int n) {if (1 = = N) return 3; if (2 = = N | | 3 = = n) return 6; return f (n-1) + f (n-2) * 2LL;} int main () {int n; IniT (); while (CIN >> N) cout << f (n) << Endl; while (CIN >> N) cout << ans[n] << Endl; return 0;}
HDU 2045 Not Easy Series (3)--lele RPG puzzle (Recursive)