比赛 山东省选(随意做) 评测结果 AAAAAAAAAA
题目名称 Bill的挑战 最终得分 100
用户昵称 .Xmz 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2010-04-12 16:58:46
显示代码纯文本
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define MOD 1000003
#define mod(x) (((x) >= MOD) ? ((x) - MOD) : (x))
#define match(a, b) ((a) == '?' || (b) == '?' || (a) == (b))

int T, N, M, K;
int Dp[55][1 << 15], AndV[55][26];
char P[15][64];

int main(void){
freopen("set.in", "r", stdin);
freopen("set.out", "w", stdout);
	for (scanf("%d", &T); T; T --){
		scanf("%d%d", &M, &K);
		for (int i = 0; i < M; i ++) scanf("%s", P[i]);
		N = strlen(P[0]);
		memset(Dp, 0, sizeof(Dp));
		Dp[0][(1 << M) - 1] = 1;
		for (int i = 0; i < N; i ++){
			for (int j = 'a'; j <= 'z'; j ++){
				AndV[i][j] = 0;
				for (int k = 0; k < M; k ++)
					if (match(P[k][i], j)) AndV[i][j] += (1 << k);
			}
		}
		for (int i = 0; i < N; i ++){
			for (int j = 0; j < (1 << M); j ++){
				if (Dp[i][j]){
					for (int k = 'a'; k <= 'z'; k ++){
						int nj = j & AndV[i][k];
						Dp[i + 1][nj] = mod(Dp[i + 1][nj] + Dp[i][j]);
					}
				}
			}
		}
		int ans = 0;
		for (int i = 0; i < (1 << M); i ++){
			int count = 0;
			for (int j = 0; j < M; j ++) count += ((i >> j) & 1);
			if (count == K) ans = mod(ans + Dp[N][i]);
		}
		printf("%d\n", ans);
	}
	return 0;
}