CF383E Vowels

CF383E

(虽然 \(24\) 有点大,但是我们有 \(4\) 秒!!!)看数据范围,\(2^{24}\) 枚举,似乎是可以做的(大概\(2 \cdot 10^7\))那么我们考虑子集dp(但是这题的复杂度好像是 \(O(n\log n)\),不知道为啥能过。)

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

typedef int ll;
const ll MAXN = 1e6+10, MAXM = 24;

ll N, M, f[(1U << MAXM) + 10], bit[(1U << MAXM) + 10];
unsigned long long ans = 0;
char ss[5];

int main() {
    for (unsigned int i = 0; i < (1U << MAXM); i++) 
        bit[i] = bit[i>>1]+(i&1);
    scanf("%d", &N);
    for (ll i = 1; i <= N; i++) {
        scanf("%s", ss+1);
        unsigned int t = 0;
        for (ll j = 1; j <= 3; j++) {
            ll now = ss[j] - 'a';
            t |= (1U << now);
        }
        for (unsigned int j = t; j; j = (j-1)&t)
            if (bit[j] & 1) f[j]++;
            else f[j]--; 
    }
    for (ll j = 0; j < MAXM; j++)
        for (unsigned int i = 0; i < (1U << MAXM); i++)
            if (i & (1U << j))
                f[i] += f[i^(1U << j)];
    for (unsigned int i = 0; i < (1U << MAXM); i++) 
        ans ^= 1ULL * f[i] * f[i];
    printf("%llu", ans);
    return 0;
}
posted @ 2020-10-16 10:53  Gensokyo_Alice  阅读(118)  评论(0编辑  收藏  举报