代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1005, M = 5005, mod = (1e9 + 7);
ll n, m, q;
char c;
string s;
ll a[M], p[N];
int main()
{
cin >> n >> m >> q;
p[1] = 1;
for (int i = 2; i <= max (n + 1, m + 1); i ++)
{
p[i] = p[i - 1] * 2;
p[i] %= mod;
}
for (int i = 1; i <= n; i ++)
{
for (int j = 1; j <= m; j ++)
{
cin >> c;
a[j] = a[j] + (int)(c - '0') * p[i];
a[j] %= mod;
}
}
while (q --)
{
ll mxx = p[n + 1], mnn = 0;
for (int i = 1; i <= m; i ++)
{
cin >> c;
if (c == '1')
mxx = min (mxx, a[i]);
else
mnn = max (mnn, a[i]);
}
ll ans = mxx - mnn;
ans %= mod;
if (ans < 0)
ans = 0;
cout << ans << endl;
}
return 0;
}
求助大佬