The main effect of the topic:
To a string of n capitals, select as many strings as possible so that each uppercase letter can appear even several times.
Ideas:
At the sight of time limit:18.000 seconds, very high without any optimization of direct violence wrote one, more than 9s, estimated to be the longest time in his history of AC embarrassment
Then think about how to optimize, found that all letters appear in the number can be expressed in binary, 0 for even, 1 for odd. In this case, all the selected string states are performed or calculated once, and the result of 0 indicates that all are even.
So it's down from 9s to 1.692s.
The competition guide introduces more efficient "halfway encounters": dividing a string into 2 parts, first calculating the XOR value of all the combinations of the previous N/2 strings, saving them in the set map, and then n/2 the characters after the enumeration, looking for the same value as before.
//UVA 1326 Jurassic remains//Direct bit operation compression #include <cstdio> #include <cstring> #include <iostr
Eam> #include <cctype> using namespace std;
int n;
Char str[30];
int st[30];
BOOL Vis[30];
int dfs (int cur, int cnt, int sta) {if (cur==n) {if (!sta) return CNT;
return-1;
} if (cur<n) {vis[cur] = true;
int res = DFS (cur+1, cnt+1, Sta^st[cur]);
if (res!=-1) return res;
Vis[cur] = false;
res = DFS (cur+1, CNT, STA);
if (res!=-1) return res;
int main () {while (~SCANF ("%d", &n)) {memset (st, 0, sizeof (ST));
for (int i=0; i<n; ++i) {scanf ("%s", str);
for (int j=0; str[j]; ++j) {st[i] ^= (1<< (str[j]-' A '));
} memset (Vis, 0, sizeof (VIS)); printf ("%d\n", DFS (0, 0, 0));
BOOL First=true;
for (int i=0; i<n; ++i) if (Vis[i]) {A-I first=false:putchar (");
printf ("%d", i+1);
} putchar (' \ n ');
return 0; }