HDU 2045 Not Easy Series (3)--lele RPG puzzle (Recursive)

Source: Internet
Author: User

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)

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.