Title Description
JYY recent operations in the study site. He found the most interesting bit computing is the exclusive OR * (xor) * operation. For an exclusive OR operation of two numbers, JYY found a conclusion: two different numbers or value of $ 0 $ if and only if they are equal. So JYY began to think, what is the nature or value will be for the exclusive $ N $ the number of it?
JYY wondered if $ 0 $ to the range of $ R-1 $ to elect $ N $ different integers, and so that $ N $ integers exclusive OR value of $ 0 $, then a number of species selected Total the way to do that? (Do not select a different order for double counting, see sample)
JYY is a computer scientist, so his mind is very, very large $ R $. In order to facilitate the expression, if R & lt we $ $ $ $ 01 written as a string, then R & lt $ $ $ is a short string of $ 01 S $ $ $ repeated K times to obtain $. For example, if $ S = 101, K = 2 $, then R & lt $ $ $ compared to the binary representation of $ 101,101. As a result of the calculation will be very large, JYY results can only tell you the total number of his choice of $ 10 ^ 9 + 7 $ modulo.
data range
$ 3 \ N \ the 7.1 \ k \ 10 ^ 5,1 \ the | S | \ le $ 50
answer
Considering the number of the selected different $ x_i $, $ and $ n-small, so consider like pressure, $ f_ {i, s} $ I $ $ represents the front position, the first state represents bit $ J $ $ $ less than or x_j equal to $ x_ {j + 1} $, special, we let $ x_ {n + 1} = R $.
String can be found for each repetition state transition paths is the same, then to take the moment.
Code
#include <bits/stdc++.h> using namespace std; const int N=130,P=1e9+7; int n,k,m,a[N],al,f[N][N]; char ch[N];bool c[N]; struct Mat{int p[N][N];}F,G,V; int X(int x){if (x>=P) x-=P;return x;} int work(int l,int r,int x){ int v=0; for (int y,z,j=1;j<n;j++) if (l&(1<<j)){ y=(r>>j)&1;z=(r>>(j-1))&1; if (y>z) return -1; if (y==z) v|=(1<<j); } if (l&1){ if ((r&1)>a[x]) return -1; if ((r&1)==a[x]) v|=1; } return v; } Mat C(Mat A,Mat B){ for (int i=0;i<al;i++) for (int j=0;j<al;j++){ V.p[i][j]=0; for (int k=0;k<al;k++) V.p[i][j]=X(V.p[i][j]+1ll*A.p[i][k]*B.p[k][j]%P); } return V; } int main(){ scanf("%d%d%s",&n,&k,ch+1);m=strlen(ch+1); for (int i=1;i<=m;i++) a[i]=ch[i]^48;al=1<<n;c[0]=1; for (int s=1;s<al;s++) c[s]=(!c[s-(s&-s)]); for (int s=0;s<al;s++){ for (int i=0;i<=m;i++) for (int j=0;j<al;j++) f[i][j]=0; f[0][s]=1; for (int i=1,j;i<=m;i++) for (int l=0;l<al;l++) if (f[i-1][l]) for (int r=0;r<al;r++) if (c[r]) if (~(j=work(l,r,i))) f[i][j]=X(f[i][j]+f[i-1][l]); for (int i=0;i<al;i++) F.p[i][s]=f[m][i]; } for (int i=0;i<al;i++) G.p[i][i]=1; for (;k;k>>=1,F=C(F,F)) if (k&1) G=C(G,F); printf("%d\n",G.p[0][al-1]); return 0; }