题目描述:

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

Examples

Input

Copy

11

Output

Copy

6

Input

Copy

01

Output

Copy

2

Input

Copy

1

Output

Copy

1

思路:

题目意思是给一个长度为n的01字符串x,然后将0到n-1的数与x做亦或,映射到另一组数,求这个形成的键值对的复杂度,根据复杂度定义,我们知道(a,b)与(c,d),当a<c&&b>d时算一个复杂度,由于我们是从小到大枚举键的,满足复杂度的第一个条件,只要再满足值是逆序的就可以了,题目就转换成了求有多少个逆序对。

我们可以来找一下规律:

n=3时,有

x=000

000=>000

001=>001

...

111=>111,值的逆序对为0,所以复杂度为零

x=001

000=>011

001=>000

010=>011

011=>010

...

111=>110,值的逆序对有4个,所以复杂度是四

以此类推,最终得到:\(a_0=0,a_1=4,a_2=8,...,a_7=28\),即\(a_x=4x\).

同理,n=2时有\(a_x=2x\).最后有:\(a_x=2^{n-1}x\).

由于是大数,需要用到快速幂和及时取余。

代码:

#include <iostream>
#include <string>
#define m 1000000007
using namespace std;
int n;
string s;
long long convert(string s)
{
long long ans = 0;
long long weight = 1;
for(int i = s.size()-1;i>=0;i--)
{
if(s[i]=='1')
{
ans = (ans+weight)%m;
}
weight = (weight%m*2)%m;
}
return ans;
}
long long q_mod(long long a,long long b,long long mod)
{
long long sum = 1;
while(b)
{
if(b&1)
{
sum = (sum%mod*a%mod)%mod;
}
a = (a%mod*a%mod)%mod;
b >>= 1;
}
return sum;
}
int main()
{
//cout << q_mod(2,3,m) << endl;
cin >> s;
n = s.size();
long long ans = convert(s);
ans = (ans%m*q_mod(2,n-1,m))%m;
cout << ans << endl;
}

Codeforces H. Malek Dance Club(找规律)的更多相关文章

  1. Malek Dance Club(递推)

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

  2. codeforces B. A and B 找规律

    Educational Codeforces Round 78 (Rated for Div. 2) 1278B - 6 B. A and B  time limit per test 1 secon ...

  3. Codeforces 870C Maximum splitting (贪心+找规律)

    <题目链接> 题目大意: 给定数字n,让你将其分成合数相加的形式,问你最多能够将其分成几个合数相加. 解题分析: 因为要将其分成合数相加的个数最多,所以自然是尽可能地将其分成尽可能小的合数 ...

  4. Codeforces Gym 100015B Ball Painting 找规律

    Ball Painting 题目连接: http://codeforces.com/gym/100015/attachments Description There are 2N white ball ...

  5. Codeforces 603A - Alternative Thinking - [字符串找规律]

    题目链接:http://codeforces.com/problemset/problem/603/A 题意: 给定一个 $01$ 串,我们“交替子序列”为这个串的一个不连续子序列,它满足任意的两个相 ...

  6. Codeforces Gym 100637B B. Lunch 找规律

    B. Lunch Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/B Des ...

  7. Codeforces 474D Flowers (线性dp 找规律)

    D. Flowers time limit per test:1.5 seconds memory limit per test:256 megabytes We saw the little gam ...

  8. codeforces D. Queue 找规律+递推

    题目链接: http://codeforces.com/problemset/problem/353/D?mobile=true H. Queue time limit per test 1 seco ...

  9. Codeforces D. Little Elephant and Interval(思维找规律数位dp)

    题目描述: Little Elephant and Interval time limit per test 2 seconds memory limit per test 256 megabytes ...

随机推荐

  1. 在日志中记录Java异常信息的正确姿势

    遇到的问题 今天遇到一个线上的BUG,在执行表单提交时失败,但是从程序日志中看不到任何异常信息. 在Review源代码时发现,当catch到异常时只是输出了e.getMessage(),如下所示: l ...

  2. YII2框架集成go!aop

    AOP实践:YII2框架本身拥有一个功能,叫做行为.它可以动态的为当前的类附加额外的功能,但这种功能在代码层级结构是静态的,有侵入性的. 下面以YII2框架集成go!aop库为例,介绍在YII2中如何 ...

  3. .NET Core sdk和runtime区别

    SDK和runtime区别 .net core Runtime[跑netcore 程序的] (CoreCLR) .net core SDK (开发工具包 [runtime(jre) + Rolysn( ...

  4. Python 入门(2):数据类型

    一 Number(数字) 1.1 数字类型的创建 a = 10 b = a b = 5 print(a) 10 print(b) 5 1.2 Number 类型转换 a = 5.2 b = 5 c = ...

  5. linux安装 uwsgi 测试 test.py 不显示hello world 的解决办法

    一般部署项目到服务器,会安装uwsgi,但是很多教程在安装它的时候会让你测试一下安装好了没,于是就有很多像我一样懵逼的少年掉进一个坑里出不来,很久.很久... 那就是最后浏览器输入ip:8000端口后 ...

  6. excel数据分析流程

    1.获取数据 2.去掉空值.空行.重复行 3.去掉无用行,筛选出需要行 4.分组数据 5.数据排序

  7. John Lemon's Haunted Jaunt(鬼屋游戏笔记)

    1.使用Unity  2019.2.3 2.角色移动的控制脚本 3.后期处理组件PostProcessLayer  (类似给相机加上了一层滤镜) 4.制作简单的怪物AI系统,使用 NAvMeshAge ...

  8. go 学习笔记 ----资源自动回收

    在释放局部资源时, 可以用defer管理 Go语言版本基于defer的Mutex用法 func safeRead(Mutex *mu) []byte { mu.Lock() defer mu.Unlo ...

  9. 西门子S7-300 设置IP、子网掩码

    =============================================== 2019/7/17_第1次修改                       ccb_warlock == ...

  10. MVC的Views中使用递归生成Html【转】

    在开发过程中往往会有一个需求,就是将一个树状的数据结构在视图中表示出来.例如最传统的多级分类,系统中有一系列根分类,每个分类中又带有一些子分类,而我们的目标便是在页面上生成一个由ul和li嵌套组成的H ...