题目:
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
Expression
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);
}
}
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- yrrf.cn 版权所有 赣ICP备2024042794号-2
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务