题目描述:

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. 金钱数友好显示 php版本

    2019年6月28日16:35:10 此方法可扩展性较好 /* * 吧金额数字转成可视化的方便读的汉字表述 */ function amountConversion(float $amount = 0 ...

  2. 小技巧——解决Github项目clone慢的问题

    设置github的项目git命令走sock代理 git config --global http.https://github.com.proxy socks5://127.0.0.1:1086(so ...

  3. IntelliJ IDEA(2018.3.5) 设置编码为utf-8编码

    位置一: File->Settings->Editor->File Encodings   位置二: File->Other Settings->Default Sett ...

  4. 手撕面试官系列(六):并发+Netty+JVM+Linux面试专题

    并发面试专题 (面试题+答案领取方式见侧边栏) 现在有 T1.T2.T3 三个线程,你怎样保证 T2 在 T1 执行完后执行,T3 在 T2 执行完后执行? 在 Java 中 Lock 接口比 syn ...

  5. 如何修改通过Anaconda安装的jupyter notebook的工作目录

    通过Anaconda安装jupyter notebook,对新手来说是一个非常明智的选择,可以避免很多不必要的麻烦! jupyter notbook默认情况下的工作目录是c:\user\...,接下来 ...

  6. Python之路【第二十八篇】:django视图层、模块层

    1.视图函数 文件在view_demo 一个视图函数简称视图,是一个简单的Python 函数,它接受Web请求并且返回Web响应.响应可以是一张网页的HTML内容,一个重定向,一个404错误,一个XM ...

  7. Python之路【第十五篇】开发FTP多线程程序

    要求: 1.用户加密认证 2.允许同时多用户登录 3.每个用户有自己的家目录,且只能访问自己的家目录 4.对用户进行磁盘配额,每个用户的可用空间不同 5.允许用户在ftp server上随意切换目录 ...

  8. [终极巨坑]golang+vue开发日记【二】,登陆界面制作(一)

    写在前面 本期内容是适合第一次使用vue或者golang开发的,内容会以实战的形式来讲解.看懂本段内容需要了解基础内容有html,css,最好可以看一下vue的基础.并且这里的每个知识点不可能详细解说 ...

  9. Python 基础 while 循环

    Python 基础 while 循环 while 循环 在生活中,我们遇到过循环的事情吧?比如循环听歌.在程序中,也是存才的,这就是流程控制语句 while 基本循环 while 条件: # 循环体 ...

  10. MySQL学习一:建表

    目标:创建三张表,学生表student(sid,name,gender), 课程表course(cid,name), 分数mark(mid, sid, cid, gender); 要求sid, cid ...