#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;
#define N 202000
#define M 200020
#define LL long long
#define B 1024
#define mod 1000000007
#define D 8
int n, a[N], d;
char s[18];
int dp[N];
bool c[1<<D][1<<D];
int f[N/B][1<<16];
void add(int &x, int y) {
x += y;
if(x >= mod) x -= mod;
}
bool cmp(int x, int y) {
for(int i = 0; i < D; ++i) {
if(x >> i & 1 ^ 1) {
if(y >> i & 1)
return 0;
}
}
return 1;
}
bool check(int x, int y) {
return c[x>>D][y>>D] && c[x&((1<<D)-1)][y&((1<<D)-1)];
}
void init() {
for(int i = 0; i < (1 << D); ++i) {
for(int j = 0; j < (1 << D); ++j) {
if(cmp(i, j)) c[i][j] = 1;
}
}
}
void mobius(int a[]) {
for(int i = 0; i < d; ++i) {
int t = (1 << d) - 1 - (1 << i);
int v = 1 << i;
for(int s = t; s; s = (s - 1) & t) {
add(a[s|v], a[s]);
}
add(a[v], a[0]);
}
}
int main() {
init();
scanf("%d%d", &n, &d);
for(int i = 1; i <= n; ++i) {
scanf("%s", s);
for(int j = 0; j < d; ++j) {
a[i] = a[i] * 2 + s[j] - 48;
}
}
for(int i = 1; i <= n; ++i) {
dp[i] = 1;
int t = i / B;
for(int j = max(1, t * B); j < i; ++j) {
if(check(a[i], a[j])) {
add(dp[i], dp[j]);
}
}
add(dp[i], f[t][a[i]]);
add(f[t+1][a[i]], dp[i]);
if((i + 1) % B == 0) {
mobius(f[t+1]);
for(int s = 0; s < (1 << d); ++s) {
add(f[t+1][s], f[t][s]);
}
}
}
int ans = 0;
for(int i = 1; i <= n; ++i) {
add(ans, dp[i]);
}
printf("%d\n", ans);
return 0;
}
ICPCCamp 2016 Day 1 - F Data Structure You've Never Heard Of (sqrt(n))
最新推荐文章于 2020-12-05 23:24:10 发布