hocchusol

 avatar
quoc14
c_cpp
19 days ago
2.9 kB
3
Indexable
Never
caidat
#include <iostream>

using namespace std;


int n, m;
char a[100][256];
int checkk[256];
int maxans = 0;
int size[100];
int countt[100];
int sumans;
void back(int index, char charstart, int target)
{
	if (index == target + 1)
	{
		if (sumans > maxans) maxans = sumans;
		return;
	}
	if (sumans <= maxans) return;
	for (char i = charstart; i <= 'z'; i++)
		if (checkk[i] == 0)
		{
			checkk[i] = 1;
			for (int ii = 1; ii <= n; ii++)
				if (a[ii][i] == 1)
				{
					if (countt[ii] == size[ii]) sumans--;
					--countt[ii];
				}
			back(index+1, i+1, target);
			for (int ii = 1; ii <= n; ii++)
				if (a[ii][i] == 1)
				{
					++countt[ii];
					if (countt[ii] == size[ii]) sumans++;
				}
			checkk[i] = 0;
		}
}


int main()
{
	checkk['u'] =  1;
	checkk['e'] =  1;
	checkk['o'] =  1;
	checkk['a'] =  1;
	checkk['i'] =  1;

	//freopen("input.txt","r",stdin);
	int ntc;
	cin >> ntc;
	for (int tc=1; tc<=ntc; tc++)
	{
		cin >> n >> m;
		for (int i = 1; i <= n; i++)
		{
			char kt1[1002];

			for (char ktt = 'a'; ktt <= 'z'; ktt++)
				a[i][ktt] = 0;

			char tmp[1002];
			cin >> tmp;
			int countsize = 0;
			int j = 0;
			while (tmp[j] != '\0')
			{
				if (a[i][tmp[j]] == 0) countsize++;
				a[i][tmp[j]] = 1;
				j++;
			}
			size[i] =  countsize;
			countt[i] = countsize;
		}

		for (int i = 1; i<=n; i++)
			if (size[i] > m) 
			{
				size[i] = size[n];
				countt[i] = countt[n];
				size[n] = 0;
				for (char ktt = 'a'; ktt <= 'z'; ktt++)
					a[i][ktt] = a[n][ktt];
				n--;
				i--;
			}

		sumans = n;
		maxans = 0;
		back(1,'a', 21-m);
		cout << "#"<< tc << " "<< maxans << endl;
	}
	return 0;
}

#include <iostream>

using namespace std;


int n, m;
char words[55][55];

char bangchucai[] = {'a', 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'}; // 21

int tmp[22];
int visit[1000];

void resetvisit() {
	for (int i = 97; i <= 123; i++) {
		visit[i] = 0;
	}
}

void tohop(int index) {
	if (index > m) {
		for (int i = 1; i <= m; i++) {
			cout << tmp[i] << " ";
		}
		cout << endl;
		return;
	}

	for (int i = 1; i <= 21; i++) {
		if (i > tmp[index - 1]) {
			tmp[index] = i;
			tohop(index + 1);
		}
	}
}

void solve(int testcase) {
	cin >> n >> m;

	for (int i = 1; i <= n; i++) {
		cin >> words[i];
	}

	int ans = 0;
	
	for (int i = 1; i <= n; i++) {
		resetvisit();
		int j = 0;
		int dem = 0;
		while (words[i][j] != '\0') {
			if (visit[j] == 0) {
				dem++;
				visit[j] = 1;
			}
			j++;
		}
		
		if (dem <= m) {
			ans++;
		}
	}

	cout << "#" << testcase << " " << ans << endl;
}


int main() {
	//freopen("Text.txt", "r", stdin);
	int t; cin >> t;

	for (int i = 1; i <= t; i++) {
		solve(i);
	}
	return 0;
}
Leave a Comment