您的位置:首页 > 其它

Codeforces 383E Vowels (容斥+莫比乌斯变换)

2016-03-22 22:38 477 查看
By doubility, contest: Codeforces Round #225 (Div. 1), problem: (E) Vowels, Accepted, #
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <vector>
using namespace std;

const int N = 1 << 24;
#define M 400030
#define mod 1000000007
#define B 234324
#define LL long long

int f[1<<24];
int n, a
;
char str[5];
int c[1<<24];

int main() {
for(int i = 1; i < (1 << 24); ++i) c[i] = c[i-(i&-i)] + 1;
scanf("%d", &n);
for(int i = 0; i < n; ++i) {
scanf("%s", str);
for(int j = 1; j < (1 << 3); ++j) {
int cnt = 0;
int s = 0;
for(int k = 0; k < 3; ++k) {
if(j >> k & 1) {
++cnt;
s |= 1 << (str[k] - 'a');
}
}
if(cnt & 1 ^ 1) f[s]--;
else f[s]++;
}
}
for(int j = 0; j < 24; ++j) {
int t = N - 1 - (1 << j);
int v = 1 << j;
for(int s = t; s; s = (s - 1) & t) {
f[s|v] += f[s];
}
f[1<<j] += f[0];
}
int ans = 0;
for(int s = 0; s < (1 << 24); ++s) {
int tmp = f[s];
ans ^= tmp * tmp;
}
printf("%d\n", ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: