# Problem

## Sample

### Input 1

5 5 1
01110
11011
10000
01010
00100
00100


### Output 1

6


### Input 2

10 10 3
0100011011
0110100101
1100010100
0111000110
1100011110
0001110100
0001101110
0110100001
1110001010
0010011101
0110011111
1101001010
0010001001


### Output2

69
0
5


## Explanation

### Explanation for Input 1

$$0 \land \ 01110_{2} \land \ 11011_{2} \vee {\ 10000}_{2}{\ \land 01010}_{2}{\ \vee 00100}_{2}$$

$$0 \vee \ 01110_{2}\ {\vee 11011}_{2}\ \land {\ 10000}_{2}{\ \ \land 01010}_{2}{\ \vee 00100}_{2}$$

$$0 \land \ 01110_{2}\ {\vee 11011}_{2} \land {\ 10000}_{2}{\ \land 01010}_{2}{\ \vee 00100}_{2}$$

$$0 \vee \ 01110_{2} \land \ 11011_{2} \land {\ 10000}_{2}{\land \ 01010}_{2}{\ \vee 00100}_{2}$$

$$0 \land \ 01110_{2}\ {\land 11011}_{2} \land {\ 10000}_{2}{\ \land 01010}_{2}{\ \vee 00100}_{2}$$

$$0 \vee \ 01110_{2}\ \vee 11011_{2} \vee {\ 10000}_{2}{\ \ \vee 01010}_{2}{\ \land 00100}_{2}$$

# Mentality

$$\&0,\&1,|0,|1$$

$$opt:\ ....011$$

$$opt<$$ $$n$$ 个数当前位构成的串

# Code

#include <cstdio>
#include <iostream>
using namespace std;
const int mod = 1e9 + 7;
int n, m, Q, tag[2], ra[5002], rb[5002], num[5001], mi[1002], t[5002];
char s[5002], q[5002];
void Mod(int &x) { x = (x % mod + mod) % mod; }
int main() {
cin >> n >> m >> Q;
mi[1] = 1;
for (int i = 2; i <= n + 1; i++)
mi[i] = (mi[i - 1] << 1) % mod;        //预处理一下幂
for (int i = 1; i <= m; i++) ra[i] = i;  //排名
for (int i = 1; i <= n; i++) {
scanf("%s", s + 1);
tag[0] = 0, tag[1] = m;  //基排的桶
for (int j = 1; j <= m; j++) {
Mod(num[j] += s[j] == '1' ? mi[i] : 0);  //处理 b 数组的值
if (s[j] == '0') tag[0]++;
}
for (int j = m; j >= 1; j--)
rb[tag[s[ra[j]] - '0']--] = ra[j];  //获取下一轮排名
swap(ra, rb);                         //更新排名
}
ra[m + 1] = m + 1;
num[m + 1] =
mi[n +
1];  //因为如果要求的结果中没有 1 ，那么操作串大小上限就是 2^n-1 了。
while (Q--) {
scanf("%s", q + 1);
int l = 0, r = m + 1;
for (int i = 1; i <= m; i++)
if (q[ra[i]] == '1') {
r = i;
break;
}  //找到最小的
for (int i = m; i >= 1; i--)
if (q[ra[i]] == '0') {
l = i;
break;
}  //找到最大的
if (l > r)
cout << "0\n";
else
printf("%d\n", ((num[ra[r]] - num[ra[l]]) % mod + mod) % mod);
}
}


posted @ 2019-03-09 12:07  洛水·锦依卫  阅读(272)  评论(0编辑  收藏  举报