#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define eb emplace_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector<int> VI; typedef basic_string<int> BI; typedef long long ll; typedef pair<int,int> PII; typedef double db; mt19937_64 mrand(114514); const ll mod=1000000007; int rnd(int x) { return mrand() % x;} ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} // head template<int MOD, int RT> struct mint { static const int mod = MOD; static constexpr mint rt() { return RT; } // primitive root for FFT int v; explicit operator int() const { return v; } // explicit -> don't silently convert to int mint():v(0) {} mint(ll _v) { v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD); if (v < 0) v += MOD; } bool operator==(const mint& o) const { return v == o.v; } friend bool operator!=(const mint& a, const mint& b) { return !(a == b); } friend bool operator<(const mint& a, const mint& b) { return a.v < b.v; } mint& operator+=(const mint& o) { if ((v += o.v) >= MOD) v -= MOD; return *this; } mint& operator-=(const mint& o) { if ((v -= o.v) < 0) v += MOD; return *this; } mint& operator*=(const mint& o) { v = int((ll)v*o.v%MOD); return *this; } mint& operator/=(const mint& o) { return (*this) *= inv(o); } friend mint pow(mint a, ll p) { mint ans = 1; assert(p >= 0); for (; p; p /= 2, a *= a) if (p&1) ans *= a; return ans; } friend mint inv(const mint& a) { assert(a.v != 0); return pow(a,MOD-2); } mint operator-() const { return mint(-v); } mint& operator++() { return *this += 1; } mint& operator--() { return *this -= 1; } friend mint operator+(mint a, const mint& b) { return a += b; } friend mint operator-(mint a, const mint& b) { return a -= b; } friend mint operator*(mint a, const mint& b) { return a *= b; } friend mint operator/(mint a, const mint& b) { return a /= b; } }; const int MOD=1000000007; using mi = mint<MOD,5>; // 5 is primitive root for both common mods namespace simp { vector<mi> fac,ifac,invn; void check(int x) { if (fac.empty()) { fac={mi(1),mi(1)}; ifac={mi(1),mi(1)}; invn={mi(0),mi(1)}; } while (SZ(fac)<=x) { int n=SZ(fac),m=SZ(fac)*2; fac.resize(m); ifac.resize(m); invn.resize(m); for (int i=n;i<m;i++) { fac[i]=fac[i-1]*mi(i); invn[i]=mi(MOD-MOD/i)*invn[MOD%i]; ifac[i]=ifac[i-1]*invn[i]; } } } mi gfac(int x) { assert(x>=0); check(x); return fac[x]; } mi ginv(int x) { assert(x>0); check(x); return invn[x]; } mi gifac(int x) { assert(x>=0); check(x); return ifac[x]; } mi binom(int n,int m) { if (m < 0 || m > n) return mi(0); return gfac(n)*gifac(m)*gifac(n - m); } } const ll mod2=mod*mod; struct Hash_table { static const int V=3000017; int fst[V],nxt[V]; int ctm,ptm[V],T; ll val[V]; array<int,3> key[V]; void init() { T=0; ctm++;} void add(array<int,3> st,ll v) { int S=(st[0]*(1ll<<40) + st[1]*(1ll<<30) + st[2])%V; if (S<0) S+=V; if (ptm[S]!=ctm) ptm[S]=ctm,fst[S]=-1; for (int j=fst[S];j!=-1;j=nxt[j]) if (key[j]==st) { val[j]+=v; if (val[j]>=mod2) val[j]-=mod2; return; } nxt[T]=fst[S],fst[S]=T,key[T]=st,val[T]=v; T++; } }; int n,m,k; char s[1111]; vector<int> ret; Hash_table dp,tmp1,tmp2; ll bi[111][111]; int main() { scanf("%d%d%d",&n,&m,&k); rep(i,0,55) { bi[i][0]=bi[i][i]=1; rep(j,1,i) bi[i][j]=(bi[i-1][j-1]+bi[i-1][j])%mod; } int M=m<<(m-1); rep(i,1,m+1) { int v; if (i==m) { v=i<<(m-1); ret.pb(M+v); ret.pb(M-v); } else { rep(j,0,1<<(m-i-1)) { v=((i-1)<<(m-1))+((2*j+1)<<(i-1)); ret.pb(M+v); ret.pb(M-v); } } } ll z=0; rep(i,0,k) { scanf("%s",s); ll v=-1; rep(i,0,m) if (s[i]!=s[0]) { v=(i-1)<<(m-1); rep(j,i+1,m) if (s[j]==s[0]) { v|=1<<(m+i-j-1); } v|=(1<<(i-1)); break; } if (v==-1) v=m<<(m-1); if (s[0]=='N') v=-v; z+=v+M; } printf("%d",(int)(z==M*k)); dp.init(); dp.add({(int)((z>>(m-1))-m*k),n-k,(int)(z%(1<<(m-1)))},1); rep(i,0,m-1) { tmp1.init(); rep(zz,0,dp.T) { auto key=dp.key[zz]; auto r=dp.val[zz]%mod; auto [ip,zbit,val]=key; rep(p1,0,n-k-zbit+1) { tmp1.add({ip,zbit,val+p1},r*bi[n-k-zbit][p1]); } } tmp2.init(); rep(zz,0,tmp1.T) { auto key=tmp1.key[zz]; auto r=tmp1.val[zz]%mod; auto [ip,zbit,val]=key; rep(pos,0,zbit+1) { tmp2.add({ip+pos*i,zbit-pos,val+pos},r*bi[zbit][pos]); } } dp.init(); rep(zz,0,tmp2.T) { auto key=tmp2.key[zz]; auto r=tmp2.val[zz]%mod; auto [ip,zbit,val]=key; rep(neg,0,zbit+1) if ((val+neg)%2==0) { dp.add({ip+neg*(-i-1),zbit-neg,(val+neg)/2},r*bi[zbit][neg]); } } } rep(i,k+1,n+1) { mi ret=0; rep(zz,0,dp.T) { auto key=dp.key[zz]; mi r=dp.val[zz]%mod; auto [ip,zbit,val]=key; int o=zbit-(n-i); if (o>=0) { rep(pos,0,o+1) { if (ip+val+pos*m+(o-pos)*(-m)==0) { ret+=r*bi[zbit][o]*bi[o][pos]; } } } } ret=ret/bi[n-k][i-k]; printf(" %d",(int)ret); } puts(""); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | #include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define eb emplace_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector<int> VI; typedef basic_string<int> BI; typedef long long ll; typedef pair<int,int> PII; typedef double db; mt19937_64 mrand(114514); const ll mod=1000000007; int rnd(int x) { return mrand() % x;} ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} // head template<int MOD, int RT> struct mint { static const int mod = MOD; static constexpr mint rt() { return RT; } // primitive root for FFT int v; explicit operator int() const { return v; } // explicit -> don't silently convert to int mint():v(0) {} mint(ll _v) { v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD); if (v < 0) v += MOD; } bool operator==(const mint& o) const { return v == o.v; } friend bool operator!=(const mint& a, const mint& b) { return !(a == b); } friend bool operator<(const mint& a, const mint& b) { return a.v < b.v; } mint& operator+=(const mint& o) { if ((v += o.v) >= MOD) v -= MOD; return *this; } mint& operator-=(const mint& o) { if ((v -= o.v) < 0) v += MOD; return *this; } mint& operator*=(const mint& o) { v = int((ll)v*o.v%MOD); return *this; } mint& operator/=(const mint& o) { return (*this) *= inv(o); } friend mint pow(mint a, ll p) { mint ans = 1; assert(p >= 0); for (; p; p /= 2, a *= a) if (p&1) ans *= a; return ans; } friend mint inv(const mint& a) { assert(a.v != 0); return pow(a,MOD-2); } mint operator-() const { return mint(-v); } mint& operator++() { return *this += 1; } mint& operator--() { return *this -= 1; } friend mint operator+(mint a, const mint& b) { return a += b; } friend mint operator-(mint a, const mint& b) { return a -= b; } friend mint operator*(mint a, const mint& b) { return a *= b; } friend mint operator/(mint a, const mint& b) { return a /= b; } }; const int MOD=1000000007; using mi = mint<MOD,5>; // 5 is primitive root for both common mods namespace simp { vector<mi> fac,ifac,invn; void check(int x) { if (fac.empty()) { fac={mi(1),mi(1)}; ifac={mi(1),mi(1)}; invn={mi(0),mi(1)}; } while (SZ(fac)<=x) { int n=SZ(fac),m=SZ(fac)*2; fac.resize(m); ifac.resize(m); invn.resize(m); for (int i=n;i<m;i++) { fac[i]=fac[i-1]*mi(i); invn[i]=mi(MOD-MOD/i)*invn[MOD%i]; ifac[i]=ifac[i-1]*invn[i]; } } } mi gfac(int x) { assert(x>=0); check(x); return fac[x]; } mi ginv(int x) { assert(x>0); check(x); return invn[x]; } mi gifac(int x) { assert(x>=0); check(x); return ifac[x]; } mi binom(int n,int m) { if (m < 0 || m > n) return mi(0); return gfac(n)*gifac(m)*gifac(n - m); } } const ll mod2=mod*mod; struct Hash_table { static const int V=3000017; int fst[V],nxt[V]; int ctm,ptm[V],T; ll val[V]; array<int,3> key[V]; void init() { T=0; ctm++;} void add(array<int,3> st,ll v) { int S=(st[0]*(1ll<<40) + st[1]*(1ll<<30) + st[2])%V; if (S<0) S+=V; if (ptm[S]!=ctm) ptm[S]=ctm,fst[S]=-1; for (int j=fst[S];j!=-1;j=nxt[j]) if (key[j]==st) { val[j]+=v; if (val[j]>=mod2) val[j]-=mod2; return; } nxt[T]=fst[S],fst[S]=T,key[T]=st,val[T]=v; T++; } }; int n,m,k; char s[1111]; vector<int> ret; Hash_table dp,tmp1,tmp2; ll bi[111][111]; int main() { scanf("%d%d%d",&n,&m,&k); rep(i,0,55) { bi[i][0]=bi[i][i]=1; rep(j,1,i) bi[i][j]=(bi[i-1][j-1]+bi[i-1][j])%mod; } int M=m<<(m-1); rep(i,1,m+1) { int v; if (i==m) { v=i<<(m-1); ret.pb(M+v); ret.pb(M-v); } else { rep(j,0,1<<(m-i-1)) { v=((i-1)<<(m-1))+((2*j+1)<<(i-1)); ret.pb(M+v); ret.pb(M-v); } } } ll z=0; rep(i,0,k) { scanf("%s",s); ll v=-1; rep(i,0,m) if (s[i]!=s[0]) { v=(i-1)<<(m-1); rep(j,i+1,m) if (s[j]==s[0]) { v|=1<<(m+i-j-1); } v|=(1<<(i-1)); break; } if (v==-1) v=m<<(m-1); if (s[0]=='N') v=-v; z+=v+M; } printf("%d",(int)(z==M*k)); dp.init(); dp.add({(int)((z>>(m-1))-m*k),n-k,(int)(z%(1<<(m-1)))},1); rep(i,0,m-1) { tmp1.init(); rep(zz,0,dp.T) { auto key=dp.key[zz]; auto r=dp.val[zz]%mod; auto [ip,zbit,val]=key; rep(p1,0,n-k-zbit+1) { tmp1.add({ip,zbit,val+p1},r*bi[n-k-zbit][p1]); } } tmp2.init(); rep(zz,0,tmp1.T) { auto key=tmp1.key[zz]; auto r=tmp1.val[zz]%mod; auto [ip,zbit,val]=key; rep(pos,0,zbit+1) { tmp2.add({ip+pos*i,zbit-pos,val+pos},r*bi[zbit][pos]); } } dp.init(); rep(zz,0,tmp2.T) { auto key=tmp2.key[zz]; auto r=tmp2.val[zz]%mod; auto [ip,zbit,val]=key; rep(neg,0,zbit+1) if ((val+neg)%2==0) { dp.add({ip+neg*(-i-1),zbit-neg,(val+neg)/2},r*bi[zbit][neg]); } } } rep(i,k+1,n+1) { mi ret=0; rep(zz,0,dp.T) { auto key=dp.key[zz]; mi r=dp.val[zz]%mod; auto [ip,zbit,val]=key; int o=zbit-(n-i); if (o>=0) { rep(pos,0,o+1) { if (ip+val+pos*m+(o-pos)*(-m)==0) { ret+=r*bi[zbit][o]*bi[o][pos]; } } } } ret=ret/bi[n-k][i-k]; printf(" %d",(int)ret); } puts(""); } |