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
#include<bits/stdc++.h>
using namespace std;


const int Mzero = 700000*2;
long long dp[2][Mzero*2];
const long long mod = 1000000007;
char slowo[30];
int tab[40][30];



int main()
{
	int n, m, k, i, j;
	scanf("%d%d%d", &n, &m, &k);
	int zero = n*m*(1<<(m-1));
	long long suma = 0;
	for(i=0;i<k;i++){
		scanf("%s", slowo+1);
		for(j=1;j<=m;j++){
			if(slowo[j]=='C')
				tab[i][j] = 1;
			else
				tab[i][j] = -1;
		}
//		for(j=1;j<=m;j++)printf("%d ", tab[i][j]);printf("\n");
//		printf("%s", slowo+1);
		long long pom = 0;
		pom+=tab[i][1];
		int it=0, flaga = 0;
		for(j=2;j<=m;j++){
			if(tab[i][j]!=tab[i][j-1])
				flaga = 1;
			pom<<=flaga;
			pom+=tab[i][j];
			it+=flaga;
		}
//		printf("%d %d\n", pom, it);
		while(it<m-1){
			pom<<=1;
			it++;
		}
//		printf("%d\n", pom);
		suma+=pom;
	}
	if(k==n){
		printf("%d\n", suma==0);
		return 0;
	}
	dp[0][zero+0] = 1;
	vector<int>sas;
	for(i=1;i<=m;i++){
		//i N
		long long pom = i<<(m-1);
//		printf("%d: %d\n", i, (1<<(m-i)));
		if(i==m){
			sas.push_back(pom);
			sas.push_back(-pom);
			continue;
		}

		for(int j = 0;j<(1<<(m-i));j+=2){
			long long pom1=0;
			for(int ij=0;ij<(m-i);ij++){
				if((j>>ij)&1)pom1=pom1*2+1;
				else
					pom1 = pom1*2-1;
			}
			pom1<<=i-1;
//			if(pom+pom1==6)printf("6: %d %d\n", i, j);
			sas.push_back(pom+pom1);
			sas.push_back(0-pom-pom1);
		}
	}
//	for(auto j: sas)printf("%d ", j);printf("\n");
	for(i=0;i<n-k;i++){
		printf("%lld ", dp[i%2][suma+zero]);
		for(int j=0;j<2*zero;j++){
			dp[(i+1)%2][j] = 0;
			for(auto s: sas)
				if(j+s>=0 && j+s<2*zero)
					dp[(i+1)%2][j] = (dp[(i+1)%2][j]+dp[i%2][j+s])%mod;
		}
	}
	printf("%lld\n", dp[(n-k)%2][suma+zero]);
}