Divide the string into two halves, before doing a violent enumeration, and throw the results into the set
The latter also acts as a violent enumeration, and each time the result goes to the set to see if there are any occurrences of the same.
If there is so different or after 0, is to meet the requirements of the topic, select the number of strings containing the most!
Such an optimization, before and after two 2^12+2^12, instantaneous time complexity of the prescription!
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #include < string> #include <stack> #include <cmath> #include <queue> #include <set> #include <map >typedef Long long ll;using namespace std;const int inf=0x3f3f3f3f;const int maxn=1e6+10;int n;int a[25];map<int,in T>table;int bitcount (int x) {return x==0? 0: (Bitcount (X/2) + (x&1));} int main () {while (scanf ("%d", &n)!=eof && N) {char s[1005];for (int i=0;i<n;++i) {scanf ("%s", &s);// printf ("%s\n", s); a[i]=0;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<<N1); ++i) {int x=0;for (int j=0;j<n1;++j) {if (I & (1<<J)) {x^=a[j];}} if (!table.count (x) | | bitcount (TABLE[X]) <bitcount (i)) table[x]=i;} int ans=0;for (int i=0;i< (1<<N2); ++i) {int x=0;for (int j=0;j<n2;++j) {if (i& (1<<j)) {x^=a[n1+j];}} if (Table.count (x) && bitcount (ANS) &Lt 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);p rintf ("\ n");} return 0;}
La 2965 Jurassic Remains (Midway encounter method)