CF 319A(Malek Dance Club-枚举Xor最高位)

C. Malek Dance Club
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

As a tradition, every year before IOI all the members of Natalia Fan Club are invited to Malek Dance Club to have a fun night together. Malek Dance Club has 2n members and coincidentally Natalia Fan Club also has 2n members. Each member of MDC is assigned a unique id i from 0 to 2n - 1. The same holds for each member of NFC.

One of the parts of this tradition is one by one dance, where each member of MDC dances with a member of NFC. A dance pair is a pair of numbers (a, b) such that member a from MDC dances with member b from NFC.

The complexity of a pairs' assignment is the number of pairs of dancing pairs (a, b) and (c, d) such that a < c and b > d.

You are given a binary number of length n named x. We know that member i from MDC dances with member  from NFC. Your task is to calculate the complexity of this assignment modulo 1000000007 (109 + 7).

Expression  denotes applying «XOR» to numbers x and y. This operation exists in all modern programming languages, for example, in C++ and Java it denotes as «^», in Pascal — «xor».

Input

The first line of input contains a binary number x of lenght n(1 ≤ n ≤ 100).

This number may contain leading zeros.

Output

Print the complexity of the given dance assignent modulo 1000000007 (109 + 7).

Sample test(s)
input
11
output
6
input
01
output
2
input
1
output
1


问题是这样

有一个二分图,i 与i xor x 相连 求交叉数

考试是时间太赶没去想(T_T)

其实这题枚举的是a和b不同的最高位(Xor后 变的那位)

1  \    /   1

0   /   \   0

最高位长这样

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
#define F (1000000007)
#define MAXN (100+10)
#define For(i,n) for(int i=1;i<=n;i++)
#define LL long long
long long ans=0;
char s[MAXN];
long long sqr(long long a){return a*a%F;}
long long bin[1000];
int main()
{
    scanf("%s",s+1);
    int n=strlen(s+1);
    bin[0]=1;For(i,999) bin[i]=(bin[i-1]*2)%F;
    For(i,n) if (s[i]=='1') ans=(ans+(bin[i-1])%F*sqr(bin[n-i]))%F;
    cout<<ans<<endl;
    return 0;
}





你可能感兴趣的:(CF 319A(Malek Dance Club-枚举Xor最高位))