【Malek Dance Club】【CodeForces - 320C】(数学+思维)

题目:

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 2nmembers 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).

Examples

Input

11

Output

6

Input

01

Output

2

Input

1

Output

1

解题报告:给序列0,1,2,……2^n-1 都异或上x ,问逆序对数。上来啥思路没有,只好暴力打表找规律。得出规律将输入的二进制数转化为十进制,然后这个数字再乘上2^(长度-1),最后得到的就是正解。

ac代码:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<stack>
#include<cstring>
using namespace std;
typedef long long ll;

const int maxn =1e6+100;

char str[maxn];

int main()
{
	while(scanf("%s",str)!=EOF)
	{
		int n=strlen(str);
		ll num=0;
		ll sum=0;
		for(int i=n-1;i>=0;i--)
		{
			if(str[i]=='1')
			{
				ll tmp=1;
				for(int i=0;i<num;i++)
				{
					tmp=tmp*2;	
					tmp%=1000000007;
				}
				sum+=tmp;
				
			}
			num++;
		}
		for(ll i=0;i<n-1;i++)
		{
			sum=sum*2;
			sum%=1000000007;
		}
		printf("%lld\n",sum);
	}
} 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值