LA 2965 Jurassic remains/Midway meeting method

Source: Internet
Author: User

Try to get as many strings as possible, each with an even number of uppercase letters

Each string can be viewed as a length of 26 occurrences of an odd number corresponding to a position of 1 even 0

is to ask for some strings of their XOR 0

n Maximum of 24

2^24 Timeout

Can enumerate the first half N/2 so the subset exists in map

And then half the enumeration to see if there is the same XOR as it is 0

Enumerate half the time to accept

#include <cstdio> #include <cstring> #include <map> using namespace std;
const int MAXN = 30;
Map <int, int> table;

int n, A[MAXN];
	int bitcount (int x) {return x = = 0? 0:bitcount (X/2) + (x&1);} int main () {char s[1000];
			while (scanf ("%d", &n) = = 1 && N) {for (int i = 0; i < n; i++) {a[i] = 0;
			scanf ("%s", s);
		for (int j = 0; s[j]; j + +) A[i] ^= (1<< (s[j]-' a '));
		} int n1 = N/2;
		int n2 = N-N1;
		Table.clear ();
			for (int i = 0; i < (1&LT;&LT;N1); i++)//first half enumerates a subset of all N1 elements {int x = 0;
			for (int j = 0; J < N1; J + +) {if (I & (1&LT;&LT;J)) x ^= a[j];
		} if (!table.count (x) | | bitcount (TABLE[X]) < Bitcount (i)//bitcount the number of 1 in the 2 binary table[x] = i;
		} int ans = 0;
			for (int i = 0; i < (1&LT;&LT;N2); i++) {int x = 0;
			for (int j = 0; J < N2; J + +) {if (I & (1&LT;&LT;J)) x ^= a[n1+j]; } if (Table.count (x) && bitcount (ans) < Bitcount (TaBLE[X]) + bitcount (i) ans = (i<<n1) ^table[x];
		} printf ("%d\n", Bitcount (ans));
		for (int i = 0; i < n; i++) {if (ans & (1<<i)) printf ("%d", i+1);
	} printf ("\ n");
} return 0; }


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.