考试的时候就拿了30points滚粗了
听说myy对这题的倒推做法很无奈,官方题解在此
正解思路真的很巧妙,也说的很清楚了
就是分别考虑每一位,会发现题解中的那个性质,然后把询问的二进制数按照排序后的位置放好,如果有1在0后面,那就肯定puts("0"),否则根据那个式子,每一位都要满足那个条件,最后范围不断缩小,就变成了两个数的差
#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
const int MAXN=1000+10,MAXM=5000+10,Mod=1e9+7;
ll total;
int n,m,q,r[MAXM];
char bin[MAXM];
template<typename T> inline void read(T &x)
{
T data=0,w=1;
char ch=0;
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')w=-1,ch=getchar();
while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
x=data*w;
}
template<typename T> inline void write(T x,char ch=' ')
{
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
if(ch!=' ')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
inline ll qexp(ll a,ll b)
{
ll res=1;
while(b)
{
if(b&1)res=res*a%Mod;
a=a*a%Mod;
b>>=1;
}
return res;
}
struct data{
int b[MAXN],id;
ll ans;
data(){ans=-1;}
inline bool operator < (const data &A) const {
for(register int i=1;i<=n;++i)
if(b[i]!=A.b[i])return b[i]>A.b[i];
return false;
};
inline ll value()
{
if(~ans)return ans;
ans=0;
for(register int i=1;i<=n;++i)(ans+=b[i]*qexp(2,n-i))%=Mod;
return ans;
}
};
data infin[MAXM];
int main()
{
freopen("hunt.in","r",stdin);
freopen("hunt.out","w",stdout);
read(n);read(m);read(q);
for(register int i=1;i<=n;++i)
{
scanf("%s",bin+1);
for(register int j=1;j<=m;++j)infin[j].b[n-i+1]=bin[j]-'0';
}
for(register int i=1;i<=m;++i)infin[i].id=i;
total=qexp(2,n);
std::sort(infin+1,infin+m+1);
while(q--)
{
scanf("%s",bin+1);
for(register int i=1;i<=m;++i)r[i]=bin[infin[i].id]-'0';
int p0=m+1,p1=0;
for(register int i=m;i>=1;--i)
if(!r[i])p0=i;
for(register int i=1;i<=m;++i)
if(r[i])p1=i;
if(p0<p1)puts("0");
else if(p0==1)write((total-infin[1].value()+Mod)%Mod,'
');
else if(p0==m+1)write(infin[m].value(),'
');
else write((infin[p0-1].value()-infin[p0].value()+Mod)%Mod,'
');
}
return 0;
}