La 2965 Jurassic Remains (Midway encounter method)

Source: Internet
Author: User

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&LT;&LT;N1); ++i) {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)) 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<<j)) {x^=a[n1+j];}} if (Table.count (x) && bitcount (ANS) &Lt Bitcount (Table[x]) +bitcount (i) {ans= (I&LT;&LT;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)

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.