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».
The first line of input contains a binary number x of lenght n, (1 ≤ n ≤ 100).
This number may contain leading zeros.
Print the complexity of the given dance assignent modulo 1000000007 (109 + 7).
11
6
01
2
1
1
题目大意:
给出一个长度为n的二进制数,现在有两队人,每个队都有2^n个人,第一队的第i个人,和第二队的第i^num(二进制数)个人进行跳舞,如果存在两对跳舞的人(a,b)和(c,d)其中保证a<c&&b>d的话,计数器加一,问一共有多少个这样的两对。
思路:
遇事不决先打表,打了表就观察到了规律。
Ans=二进制数转成十进制数之后*2^(n-1);
过程维护一下取模就行了。
Ac代码:
#include<stdio.h>
#include<math.h>
#include<string.h>
using namespace std;
#define ll __int64
char a[150000];
int main()
{
while(~scanf("%s",a))
{
ll num=0;
ll cont=0;
ll n=strlen(a);
for(ll i=n-1;i>=0;i--)
{
if(a[i]=='1')
{
ll tmp=1;
for(ll j=0;j<cont;j++)
{
tmp*=2;
tmp%=1000000007;
}
num+=tmp;
}
cont++;
}
for(ll i=0;i<n-1;i++)
{
num=num*2;
num%=1000000007;
}
printf("%I64d\n",num);
}
}