Alice and Bobo are playing a game on a graph with nn vertices numbered with 0,1,…,(n−1)0,1,…,(n−1).
The vertex numbered with ii is associated with weight 2i2i.
The game is played as follows.
Firstly, Alice chooses a (possibly empty) subset of the n(n−1)2n(n−1)2 edges.
Subsequently Bobo chooses a (possibly empty) subset of the nn 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 SS, 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 kk (i.e. S=kS=k), modulo (109+7)(109+7).
Input
The input consists of several test cases and is terminated by end-of-file.
Each test case contains two integers nn and kk.
For convenience, the number kk is given in its binary notation.
Output
For each test case, print an integer which denotes the result.
## Constraint
* 1≤n≤1051≤n≤105
* 0≤k<2n0≤k<2n
* The sum of nn does not exceed 250,000250,000.
Sample Input
3 1 4 101 10 101010101
Sample Output
3 12 239344570
题意:有一个n个顶点的完全图,第i个顶点的权值为2^i,Alice选了一个边集,Bob会选择一个权值最小的点集,使得Alice的集合中任意一条边的两个顶点至少有个一被覆盖,先给出Bob选的点集,问Alice有多少种选法
思路:每个被选点至少要和一个权值比他大的非被选点连边,和权值比他小的点可连可不连
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
const int M = 1e6 + 7;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
ll f[N];
int main() {
f[0] = 1;
for(int i = 1; i < N; ++i) f[i] = f[i - 1] * 2 % mod;
int n;
while(~scanf("%d", &n)) {
string s;
cin >> s;
int siz = s.size();
ll ans = 1, las = n - siz;
for(int i = 0; i < siz; ++i) {
if(s[i] == '1') {
ans = ans * (f[las] - 1 + mod) % mod * f[siz - i - 1] % mod;
}
else las++;
}
printf("%lld\n", ans);
}
return 0;
}