UVA 1326 B

来源:互联网 发布:淘宝富光保温杯 编辑:程序博客网 时间:2024/06/01 07:41

不用位运算会超时

#include <cstdio>using namespace std;int main() {    char str[30];    int n, a[30], cnt, ans;    while (~scanf("%d", &n)) {        for (int i = 0; i < n; i++) {            scanf("%s", str);            a[i] = 0;            for (int j = 0; str[j]; j++) a[i] ^= (1<<(str[j] - 'A'));        }        cnt = ans = 0;        for (int i = 1; i < (1<<n); i++) {            int t = 0, c = 0;            for (int j = 0; j < n; j++) if (i & (1<<j)) t ^= a[j], c++;            if (t == 0 && c > cnt) {                cnt = c, ans = i;            }        }        int flag = 0;        printf("%d\n", cnt);        for (int i = 0; i < n; i++) {            if (ans & (1<<i)) {                if (flag++) printf(" ");                printf("%d", i + 1);            }        }        printf("\n");    }}


原创粉丝点击