#include <bits/stdc++.h> using namespace std; #define fwd(i, a, n) for (int i = (a); i < (n); i ++) #define rep(i, n) fwd(i, 0, n) #define all(X) begin(X), end(X) #define sz(X) ((int)X.size()) #define st first #define nd second #define pii pair<int, int> #define vi vector<int> #define ll long long #ifdef LOC auto &operator<<(auto &out, pair<auto, auto> a) { return out << "(" << a.st << ", " << a.nd << ")"; } auto &operator<<(auto &out, auto a) { out << "{"; for (auto b : a) out << b << ", "; return out << "}"; } void dump(auto... x) { ((cerr << x << ", "), ...) << '\n'; } #define debug(x...) cerr << __LINE__ << ": [" #x "]: ", dump(x) #else #define debug(...) 0 #endif const ll MOD = 1e9 + 7; ll val(vector<ll>& v, int pos){ if(pos < 0 || pos >= sz(v))return 0; return v[pos]; } int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, m, k; cin>>n>>m>>k; int sum = 0; rep(i, k){ int a = 0; string str; cin>>str; int x = 1; if(str[0] == 'C'){ a = 1; }else{ a = -1; } bool git = true; for(int j = 1; j < m; j++){ if(str[j] != str[j-1])git = false; a *= 2; if(git)x*= 2; if(str[j] == 'C'){ a += x; }else{ a -= x; } } debug(a); sum += a; } debug(sum); if(k == n){ if(sum == 0){ cout<<"1\n"; }else{ cout<<"0\n"; } return 0; } int K = m * (n - k) * (1<<(m-1)) + 3; vector<vector<ll>> dp(n-k + 1, vector<ll>(2*K + 1, 0)); dp[0][K] = 1; vector<vector<ll>> pref(m+1, vector<ll>(2*K+1, 0)); vector<vector<ll>> suf(m+1, vector<ll>(2*K + 1, 0)); for(int x = 1; x <= n-k; x++){ rep(j, m+1){ for(int i = 0; i < (1<<j) && i < 2*K + 1; i++){ pref[j][i] = dp[x-1][i]; } for(int i = (1<<j); i < 2*K + 1; i++){ pref[j][i] = dp[x-1][i] + pref[j][i-(1<<j)]; } for(int i = 2*K; i > 2*K - (1<<j) && i >= 0; i--){ suf[j][i] = dp[x-1][i]; } for(int i = 2*K - (1<<j); i >= 0; i--){ suf[j][i] = dp[x-1][i] + suf[j][i + (1<<j)]; } } //debug(pref); rep(j, m){ int d1 = (1<<j) + j * (1<<(m-1)); int d2 = (j+1) * (1<<(m-1)) + (1<<(j+1)) - (1<<j); if(j == m-1)d2 = m * (1<<(m-1)) + (1<<(j+1)); //debug(j, d1, d2); //debug(pref[j+1]); //debug(suf[j+1]); for(int i =0; i < 2*K + 1; i++){ dp[x][i] += val(pref[j+1], i-d1) - val(pref[j+1], i - d2); dp[x][i] += val(suf[j+1], i + d1) - val(suf[j+1], i + d2); } } for(int i =0; i < 2*K; i++)dp[x][i] %= MOD; } /*for(int x = 0; x <= n-k; x++){ for(int i = 0; i <= K; i++)cout<<dp[x][i + K]<<" "; cout<<"\n"; }*/ //for(int x = 0; x <= n-k; x++)debug(dp[x]); for(int x = 0; x <= n-k; x++){ cout<<dp[x][sum + K]<<" "; } cout<<"\n"; return 0; }
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 | #include <bits/stdc++.h> using namespace std; #define fwd(i, a, n) for (int i = (a); i < (n); i ++) #define rep(i, n) fwd(i, 0, n) #define all(X) begin(X), end(X) #define sz(X) ((int)X.size()) #define st first #define nd second #define pii pair<int, int> #define vi vector<int> #define ll long long #ifdef LOC auto &operator<<(auto &out, pair<auto, auto> a) { return out << "(" << a.st << ", " << a.nd << ")"; } auto &operator<<(auto &out, auto a) { out << "{"; for (auto b : a) out << b << ", "; return out << "}"; } void dump(auto... x) { ((cerr << x << ", "), ...) << '\n'; } #define debug(x...) cerr << __LINE__ << ": [" #x "]: ", dump(x) #else #define debug(...) 0 #endif const ll MOD = 1e9 + 7; ll val(vector<ll>& v, int pos){ if(pos < 0 || pos >= sz(v))return 0; return v[pos]; } int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, m, k; cin>>n>>m>>k; int sum = 0; rep(i, k){ int a = 0; string str; cin>>str; int x = 1; if(str[0] == 'C'){ a = 1; }else{ a = -1; } bool git = true; for(int j = 1; j < m; j++){ if(str[j] != str[j-1])git = false; a *= 2; if(git)x*= 2; if(str[j] == 'C'){ a += x; }else{ a -= x; } } debug(a); sum += a; } debug(sum); if(k == n){ if(sum == 0){ cout<<"1\n"; }else{ cout<<"0\n"; } return 0; } int K = m * (n - k) * (1<<(m-1)) + 3; vector<vector<ll>> dp(n-k + 1, vector<ll>(2*K + 1, 0)); dp[0][K] = 1; vector<vector<ll>> pref(m+1, vector<ll>(2*K+1, 0)); vector<vector<ll>> suf(m+1, vector<ll>(2*K + 1, 0)); for(int x = 1; x <= n-k; x++){ rep(j, m+1){ for(int i = 0; i < (1<<j) && i < 2*K + 1; i++){ pref[j][i] = dp[x-1][i]; } for(int i = (1<<j); i < 2*K + 1; i++){ pref[j][i] = dp[x-1][i] + pref[j][i-(1<<j)]; } for(int i = 2*K; i > 2*K - (1<<j) && i >= 0; i--){ suf[j][i] = dp[x-1][i]; } for(int i = 2*K - (1<<j); i >= 0; i--){ suf[j][i] = dp[x-1][i] + suf[j][i + (1<<j)]; } } //debug(pref); rep(j, m){ int d1 = (1<<j) + j * (1<<(m-1)); int d2 = (j+1) * (1<<(m-1)) + (1<<(j+1)) - (1<<j); if(j == m-1)d2 = m * (1<<(m-1)) + (1<<(j+1)); //debug(j, d1, d2); //debug(pref[j+1]); //debug(suf[j+1]); for(int i =0; i < 2*K + 1; i++){ dp[x][i] += val(pref[j+1], i-d1) - val(pref[j+1], i - d2); dp[x][i] += val(suf[j+1], i + d1) - val(suf[j+1], i + d2); } } for(int i =0; i < 2*K; i++)dp[x][i] %= MOD; } /*for(int x = 0; x <= n-k; x++){ for(int i = 0; i <= K; i++)cout<<dp[x][i + K]<<" "; cout<<"\n"; }*/ //for(int x = 0; x <= n-k; x++)debug(dp[x]); for(int x = 0; x <= n-k; x++){ cout<<dp[x][sum + K]<<" "; } cout<<"\n"; return 0; } |