Alice and Bobo are playing a game on a graph with
n vertices numbered with
0,1,…,(n−1).
The vertex numbered with i is associated with weight 2i.
The game is played as follows.
Firstly, Alice chooses a (possibly empty) subset of the n(n−1)2 edges.
Subsequently Bobo chooses a (possibly empty) subset of the n vertices to *cover* the edges chosen by Alice.
An edge is *covered* if one of its two ends is chosen by Bobo.
As Bobo is smart, he will choose a subset of vertices whose sum of weights, denoted as S, is minimum.
Alice would like to know the number of subsets of edges where Bobo will choose a subset whose sum of weights is exactly k (i.e. S=k), modulo (109+7)
Each test case contains two integers n and k.
For convenience, the number k is given in its binary notation.
Output For each test case, print an integer which denotes the result.
## Constraint
* 1≤n≤105
* 0≤k<2n
* The sum of n does not exceed 250,000.
Sample Input
The vertex numbered with i is associated with weight 2i.
The game is played as follows.
Firstly, Alice chooses a (possibly empty) subset of the n(n−1)2 edges.
Subsequently Bobo chooses a (possibly empty) subset of the n vertices to *cover* the edges chosen by Alice.
An edge is *covered* if one of its two ends is chosen by Bobo.
As Bobo is smart, he will choose a subset of vertices whose sum of weights, denoted as S, is minimum.
Alice would like to know the number of subsets of edges where Bobo will choose a subset whose sum of weights is exactly k (i.e. S=k), modulo (109+7)
.
Input The input consists of several test cases and is terminated by end-of-file.
Each test case contains two integers n and k.
For convenience, the number k is given in its binary notation.
Output For each test case, print an integer which denotes the result.
## Constraint
* 1≤n≤105
* 0≤k<2n
* The sum of n does not exceed 250,000.
Sample Input
3 1 4 101 10 101010101Sample Output
3 12 239344570
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pi; typedef pair<ll,ll> pl; typedef pair<ld,ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; #define rep(i,a,b) for(int i=a;i<=b;i++) #define per(i,a,b) for(int i=b-1;i>=a;i--) #define all(a) (a).begin(),(a).end() #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define eb emplace_back #define f first #define s second ll rd(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } const int N=1e5+10; const int mod=(int)1e9+7; char c[N]; inline ll add(ll abc){ if(abc>mod)abc-=mod; return abc; } ll power(ll a,ll b) { ll ans = 1; a %= mod; while(b) { if(b & 1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans; } int main(){ #ifdef happy freopen("in.txt","r",stdin); #endif int n; while(~scanf("%d %s",&n,c)){ string s(c); reverse(all(s)); int len=s.size(); vi a; for(int i=0;i<len;i++) if(s[i]=='1'){ a.push_back(i); } reverse(all(a)); ll ans=1; len=a.size(); //n=n-1; for(int i=0;i<len;i++){ ll t=power(2.0,n-a[i]-i-1)-1; t = (t%mod + mod)%mod; ans=(ans*t)%mod; //cout<<ans<<endl; t=power(2.0,i+a[i]-(len-i-1)); ans=(ans*t)%mod; //cout<<ans<<endl; } cout<<ans<<endl; /* for(auto u:a){ printf("%d ",u); } puts(""); */ } return 0; }