POJ 1903 Jurassic Remains 纯暴力

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<math.h>
#include<string>
#include<stdio.h>
#include<cstring>
#include<sstream>
#include<algorithm>
using namespace std;
string ts(int a)
{
	string s;
	stringstream ss(s);
	ss << a;
	return ss.str();
}
int main()
{
	int templen[24], len[24], tail;
	int sum;
	int b[24][26];
	int a[26];
	int num, mx, tempmax;
	string join;
	int n;
	int i, j, k;
	for (; cin >> n;)
	{
		memset(b, 0, sizeof(b));
		memset(a, 0, sizeof(a));
		for (i = 0; i < n; i++)
		{
			cin >> join;
			for (j = 0; join[j] != '\0'; j++)
				b[i][join[j] - 'A'] = 1;
			join = "\0";
			for (j = 0; j < 26; j++)
			if (b[i][j] == 1)
				a[i] += pow(2, j);
		}
		mx = 0;
		sum = 0;
		tempmax = 0;
		int A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, V, U, W, X, Y, Z;
		for (A = 0; A < 2; A++)
		{
			for (B = 0; B < 2; B++)
			{
				for (C = 0; C < 2; C++)
				{
					for (D = 0; D < 2; D++)
					{
						for (E = 0; E < 2; E++)
						{
							for (F = 0; F < 2; F++)
							{
								for (G = 0; G < 2; G++)
								{
									for (H = 0; H < 2; H++)
									{
										for (I = 0; I < 2; I++)
										{
											for (J = 0; J < 2; J++)
											{
												for (K = 0; K < 2; K++)
												{
													for (L = 0; L < 2; L++)
													{
														for (M = 0; M < 2; M++)
														{
															for (N = 0; N < 2; N++)
															{
																for (O = 0; O < 2; O++)
																{
																	for (P = 0; P < 2; P++)
																	{
																		for (Q = 0; Q < 2; Q++)
																		{
																			for (R = 0; R < 2; R++)
																			{
																				for (S = 0; S < 2; S++)
																				{
																					for (T = 0; T < 2; T++)
																					{
																						for (U = 0; U < 2; U++)
																						{
																							for (V = 0; V < 2; V++)
																							{
																								for (W = 0; W < 2; W++)
																								{
																									for (X = 0; X < 2; X++)
																									{
																										sum = a[0] * A^a[1] * B^a[2] * C^a[3] * D^a[4] * E^a[5] * F^a[6] * G^a[7] * H^a[8] * I^a[9] * J^a[10] * K^a[11] * L^a[12] * M^a[13] * N^a[14] * O^a[15] * P^a[16] * Q^a[17] * R^a[18] * S^a[19] * T^a[20] * U^a[21] * V^a[22] * W^a[23] * X;
																										if (sum == 0)
																										{
																											templen[0] = A;
																											templen[1] = B;
																											templen[2] = C;
																											templen[3] = D;
																											templen[4] = E;
																											templen[5] = F;
																											templen[6] = G;
																											templen[7] = H;
																											templen[8] = I;
																											templen[9] = J;
																											templen[10] = K;
																											templen[11] = L;
																											templen[12] = M;
																											templen[13] = N;
																											templen[14] = O;
																											templen[15] = P;
																											templen[16] = Q;
																											templen[17] = R;
																											templen[18] = S;
																											templen[19] = T;
																											templen[20] = U;
																											templen[21] = V;
																											templen[22] = W;
																											templen[23] = X;
																											for (j = 0; j < n; j++)
																											if (templen[j] == 1)
																												tempmax++;
																											if (tempmax>mx)
																											{
																												for (j = 0; j < n; j++)
																													len[j] = templen[j];
																												mx = tempmax;
																											}
																										}
																										sum = 0;
																										tempmax = 0;
																									}
																								}
																							}
																						}
																					}
																				}
																			}
																		}
																	}
																}
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
		cout << mx << endl;
		for (i = 0; i < n && mx; i++)
		{
			if (len[i] == 1)
			{
				cout << i + 1;
				mx--;
			if (mx)
				cout << " ";
			}
		}
		cout << endl;
	}
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值