[HIHO1318] Illegal binary (dynamic programming)

Source: Internet
Author: User

Title Link: http://hihocoder.com/problemset/problem/1318

Test instructions: It's a DP question. When considering a binary number of I bits, there are only two cases: the newly added one is 0 or 1.

At 0, then this one does not contribute to the number, when the value and the i-1 bit are the same DP (I-1).

At 1, take a look at the second-to-last:

11: Regardless of the previous n-2 bit, this number is illegal, the answer is 2^ (i-2).

10 of the situation: 1 did not contribute, because by the 0 split opened. The answer is DP (I-2).

So when I bit, the answer consisted of: DP (I-1), DP (I-2), 2^ (i-2).

1 /*2 ━━━━━┒ギリギリ♂eye! 3 ┓┏┓┏┓┃キリキリ♂mind! 4 ┛┗┛┗┛┃\0/5 ┓┏┓┏┓┃/6 ┛┗┛┗┛┃ノ)7 ┓┏┓┏┓┃8 ┛┗┛┗┛┃9 ┓┏┓┏┓┃Ten ┛┗┛┗┛┃ One ┓┏┓┏┓┃ A ┛┗┛┗┛┃ - ┓┏┓┏┓┃ - ┃┃┃┃┃┃ the ┻┻┻┻┻┻ - */ -#include <algorithm> -#include <iostream> +#include <iomanip> -#include <cstring> +#include <climits> A#include <complex> at#include <fstream> -#include <cassert> -#include <cstdio> -#include <bitset> -#include <vector> -#include <deque> in#include <queue> -#include <stack> to#include <ctime> +#include <Set> -#include <map> the#include <cmath> * using namespacestd; $ #defineFr FirstPanax Notoginseng #defineSC Second - #defineCL Clear the #defineBUG puts ("Here!!!") + #defineW (a) while (a--) A #definePB (a) push_back (a) the #defineRint (a) scanf ("%d", &a) + #defineRll (a) scanf ("%lld", &a) - #defineRs (a) scanf ("%s", a) $ #defineCIN (a) CIN >> a $ #defineFRead () freopen ("in", "R", stdin) - #defineFWrite () freopen ("Out", "w", stdout) - #defineRep (i, Len) for (int i = 0; i < (len); i++) the #defineFor (I, A, Len) for (int i = (a); I < (len); i++) - #defineCls (a) memset ((a), 0, sizeof (a))Wuyi #defineCLR (A, X) memset ((a), (x), sizeof (a)) the #defineFull (a) memset ((a), 0x7f7f, sizeof (a)) - #defineLRT RT << 1 Wu #defineRRT RT << 1 | 1 - #definePi 3.14159265359 About #defineRT return $ #defineLowbit (x) x & (-X) - #defineOnenum (x) __builtin_popcount (x) -typedefLong LongLL; -typedefLong DoubleLD; Atypedef unsignedLong LongULL; +typedef pair<int,int>PII; thetypedef pair<string,int>psi; -typedef PAIR&LT;LL, Ll>PLL; $typedef map<string,int>MSI; thetypedef vector<int>VI; thetypedef vector<ll>VL; thetypedef vector<vl>VVL; thetypedef vector<BOOL>vb; -  in Const intMAXN = the; the ConstLL mod =1000000007; the LL DP[MAXN]; About intN; the  the ll Quickmul (ll X, ll N) { theLL ret =1; +      while(n) { -         if(N &1) ret = (ret * x)%MoD; theN >>=1;Bayix = (x * x)%MoD; the     } the     returnret; - } -  the  the intMain () { the     //FRead (); the Cls (DP); -dp[2] =1; dp[3] =3; thefor (I,4,101) { theDp[i] = (((dp[i-1] + dp[i-2]% MoD) + Quickmul (2, I-2)) %MoD; the     }94      while(~rint (n)) cout << Dp[n] <<Endl; theRt0; the}

[HIHO1318] Illegal binary (dynamic programming)

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.