Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 500500 points

Problem Statement

You are given a positive integer LL in base two. How many pairs of non-negative integers (a,b)(a,b) satisfy the following conditions?

  • a+b≤La+b≤L
  • a+b=a XOR ba+b=a XOR b

Since there can be extremely many such pairs, print the count modulo 109+7109+7.

 

What is XOR?

 

Constraints

  • LL is given in base two, without leading zeros.
  • 1≤L<2100 0011≤L<2100 001

Input

Input is given from Standard Input in the following format:

LL

Output

Print the number of pairs (a,b)(a,b) that satisfy the conditions, modulo 109+7109+7.


Sample Input 1 Copy

Copy

10

Sample Output 1 Copy

Copy

5

Five pairs (a,b)(a,b) satisfy the conditions: (0,0),(0,1),(1,0),(0,2)(0,0),(0,1),(1,0),(0,2) and (2,0)(2,0).


Sample Input 2 Copy

Copy

1111111111111111111

Sample Output 2 Copy

Copy

162261460

 

类似数位dp的dp方法

dp[i][1]代表第i为被限制时的方法数

dp[I][0]代表第i未被限制时的方法数

被限制的话对于下一位我们是不能任意取的

而不被限制我们则可以根据上一个不被限制的方法*3推得

我们考虑几种转移情况

i为1时 可以由限制转移到非限制 而对于限制到限制则可*2推出

代码

#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
long long dp[100005][2];
int main()
{
    char s[100005];
    cin>>s+1;
    dp[0][1]=1;
    dp[0][0]=0;
    int n=strlen(s+1);
    for(int i=1;s[i];i++)
    {
        dp[i][0]=(dp[i-1][0]*3)%mod;
        if(s[i]=='1')
        {
            dp[i][1]=(dp[i-1][1]*2)%mod;
            dp[i][0]+=dp[i-1][1];
            dp[i][0]=(dp[i][0])%mod;
        }
        else
        {
            dp[i][1]=dp[i-1][1];
        }
    }
    printf("%lld\n",(dp[n][1]+dp[n][0])%mod);
}