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;
}





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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值