⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1264.cpp

📁 这是哈尔滨工业大学acmOJ的源代码
💻 CPP
字号:
/* This Code is Submitted by wywcgs for Problem 1264 on 2006-09-19 at 13:19:58 */
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef unsigned int uint;
const int N = 640;
const int L = 16;

class Word {
public:
	char cbn[L];
	Word() {}
	Word(char* str) { strcpy(cbn, str); }
	void make() { scanf("%s", cbn); }
	bool operator <(const Word& w) const { return strcmp(cbn, w.cbn) < 0; }
};

typedef pair<Word*, Word*> pww;

int wl;
uint comb[N];
pww nxt[N];
Word w[N];

bool cmp(const Word& w1, const Word& w2) { return strncmp(w1.cbn, w2.cbn, wl) < 0; }

int main()
{
	int n, l, m;
	
	while(scanf("%d %d %d", &n, &l, &m) != EOF && n != 0) {
		for(int i = 0; i < m; i++) w[i].make();
		sort(w, w+m); wl = strlen(w[0].cbn)-1;
		for(int i = 0; i < m; i++) nxt[i] = equal_range(w, w+m, Word(w[i].cbn+1), cmp);
		if(wl+1 > l) { printf("0\n"); continue; }
		for(int i = 0; i < m; i++) comb[i] = 1;
		for(int i = wl+1; i < l; i++) {
			uint tmp[N] = { 0 };
			for(int j = 0; j < m; j++)
				for(Word* k = nxt[j].first; k < nxt[j].second; k++)
					tmp[k-w] += comb[j];
			memcpy(comb, tmp, sizeof(comb));
		}
		uint r = 0;
		for(int i = 0; i < m; i++) r += comb[i];
		printf("%u\n", r);
	}
	
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -