比赛 4043级2023省选模拟赛7 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 Problem Setting 最终得分 100
用户昵称 op_组撒头屯 运行时间 11.410 s
代码语言 C++ 内存使用 48.58 MiB
提交时间 2023-03-29 12:01:36
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
const int N=1000000+5;
const ll mod=1000000007;
int n,m;
char s[22][N];
int d[(1<<20)+5];
ll fac[N],inv[N],f[(1<<20)+5];
ll fst(ll x,ll y){
    ll ans=1;
    while(y){
        if (y&1)ans=ans*x%mod;
        x=x*x%mod;y>>=1;
    }return ans;
}
int main(){
	freopen ("wentiji.in","r",stdin);
	freopen ("wentiji.out","w",stdout);
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++){
	    scanf("%s",s[i]+1);
    }
    for (int i=1;i<=n;i++){
        int x=0;
	    for (int j=m;j>=1;j--)x=(x<<1)|(s[j][i]=='H');
	    d[x]++;
    }
    fac[0]=1;ll ans=0;
    for (int i=1;i<=n;i++)fac[i]=fac[i-1]*i%mod;
    inv[n]=fst(fac[n],mod-2);
    for (int i=n-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
    for (int i=0;i<(1<<m);i++){
        if (!d[i])continue;
        ll con=0;
        for (int j=1;j<=d[i];j++)(con+=inv[d[i]-j])%=mod;
        (con*=fac[d[i]])%=mod;
        for (int j=(i-1)&i;;j=(j-1)&i){
            (f[i]+=f[j])%=mod;
            if (j<=0)break;
        }
        f[i]++;
        (f[i]*=con)%=mod;(ans+=f[i])%=mod;
        //cout<<i<<' '<<con<<" "<<f[i]<<endl;
    }
    printf("%lld\n",ans);
}