zoukankan      html  css  js  c++  java
  • [HIHO1318]非法二进制(动态规划)

    题目链接:http://hihocoder.com/problemset/problem/1318

    题意:是个dp题。考虑二进制数为i位的时候,无非有两种情况:新添加的一位为0或者1。

    为0的时候,那此时这一位对该数没有贡献,此时值和i-1位的时候是相同的dp(i-1)。

    为1的时候,还要看一下倒数第二位是什么:

    11的情况:不管前面的n-2位是什么,这个数都是非法的,答案是2^(i-2)。

    10的情况:1没贡献,因为被0分割开了。答案是dp(i-2)。

    所以i位的时候,答案组成为:dp(i-1),dp(i-2),2^(i-2)。

     1 /*
     2 ━━━━━┒ギリギリ♂ eye!
     3 ┓┏┓┏┓┃キリキリ♂ mind!
     4 ┛┗┛┗┛┃\○/
     5 ┓┏┓┏┓┃ /
     6 ┛┗┛┗┛┃ノ)
     7 ┓┏┓┏┓┃
     8 ┛┗┛┗┛┃
     9 ┓┏┓┏┓┃
    10 ┛┗┛┗┛┃
    11 ┓┏┓┏┓┃
    12 ┛┗┛┗┛┃
    13 ┓┏┓┏┓┃
    14 ┃┃┃┃┃┃
    15 ┻┻┻┻┻┻
    16 */
    17 #include <algorithm>
    18 #include <iostream>
    19 #include <iomanip>
    20 #include <cstring>
    21 #include <climits>
    22 #include <complex>
    23 #include <fstream>
    24 #include <cassert>
    25 #include <cstdio>
    26 #include <bitset>
    27 #include <vector>
    28 #include <deque>
    29 #include <queue>
    30 #include <stack>
    31 #include <ctime>
    32 #include <set>
    33 #include <map>
    34 #include <cmath>
    35 using namespace std;
    36 #define fr first
    37 #define sc second
    38 #define cl clear
    39 #define BUG puts("here!!!")
    40 #define W(a) while(a--)
    41 #define pb(a) push_back(a)
    42 #define Rint(a) scanf("%d", &a)
    43 #define Rll(a) scanf("%lld", &a)
    44 #define Rs(a) scanf("%s", a)
    45 #define Cin(a) cin >> a
    46 #define FRead() freopen("in", "r", stdin)
    47 #define FWrite() freopen("out", "w", stdout)
    48 #define Rep(i, len) for(int i = 0; i < (len); i++)
    49 #define For(i, a, len) for(int i = (a); i < (len); i++)
    50 #define Cls(a) memset((a), 0, sizeof(a))
    51 #define Clr(a, x) memset((a), (x), sizeof(a))
    52 #define Full(a) memset((a), 0x7f7f, sizeof(a))
    53 #define lrt rt << 1
    54 #define rrt rt << 1 | 1
    55 #define pi 3.14159265359
    56 #define RT return
    57 #define lowbit(x) x & (-x)
    58 #define onenum(x) __builtin_popcount(x)
    59 typedef long long LL;
    60 typedef long double LD;
    61 typedef unsigned long long ULL;
    62 typedef pair<int, int> pii;
    63 typedef pair<string, int> psi;
    64 typedef pair<LL, LL> pll;
    65 typedef map<string, int> msi;
    66 typedef vector<int> vi;
    67 typedef vector<LL> vl;
    68 typedef vector<vl> vvl;
    69 typedef vector<bool> vb;
    70 
    71 const int maxn = 110;
    72 const LL mod = 1000000007;
    73 LL dp[maxn];
    74 int n;
    75 
    76 LL quickmul(LL x, LL n) {
    77     LL ret = 1;
    78     while(n) {
    79         if(n & 1) ret = (ret * x) % mod;
    80         n >>= 1;
    81         x = (x * x) % mod;
    82     }
    83     return ret;
    84 }
    85 
    86 
    87 int main() {
    88     // FRead();
    89     Cls(dp);
    90     dp[2] = 1; dp[3] = 3;
    91     For(i, 4, 101) {
    92         dp[i] = (((dp[i-1] + dp[i-2]) % mod) + quickmul(2, i-2)) % mod;
    93     }
    94     while(~Rint(n)) cout << dp[n] << endl;
    95     RT 0;
    96 }
  • 相关阅读:
    zabbix 3.2.2 server端添加客户端主机配置 (四)
    zabbix 3.2.2 server web展示如何显示中文 (三)
    zabbix 3.2.2 agent端(源码包)安装部署 (二)
    zabbix 3.2.2 server端(源码包)安装部署 (一)
    centos执行apt-get提示不存在
    用简单的方法学习ES6
    PHP+MySQL存储数据出现中文乱码的问题
    CentOS 6.0 系统 LAMP(Apache+MySQL+PHP)安装步骤
    mysql查询索引
    线程和进程
  • 原文地址:https://www.cnblogs.com/kirai/p/5578789.html
Copyright © 2011-2022 走看看