bzoj 1442: [Poi2006]Crystal

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1442
思路:好久没做题了写道水题压压惊,感觉都有点生疏了。
这样考虑,我们采取调整法,考虑到如果有一个数特别大,那么除此之外随便选,根据这个性质,我们枚举最先出现这种情况的是哪一位 i ,也就是说至少存在一个数取得Xi和对应 Ai lcp 恰好是从高到低的 i1 位,而其它的 lcp 要在第 i 位之后,这样就可以dp了,为了避免重复要加一维记录是否已经存在这样的数。
注意discuss里补充的题目描述。
复杂度: O(nlogn)

代码:

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#define C 33
#define N 52
using namespace std;
typedef unsigned long long LL;
LL f[2][2][2],A[N],n,bin[C << 1],ans;
//f[i][0/1][0/1]当前位xor为0/1,是否已经有位置由1变为0 
void init(){
    scanf("%llu",&n);
    for (int i = 1;i <= n; ++i) scanf("%llu",&A[i]);
    bin[0] = 1;
    for (int i = 1;i <= 62; ++i) bin[i] = bin[i - 1] << 1;
}

void DO_IT(){
    LL s1,s2,t;
    ans = 0; s1 = 0;
    for (int i = 1;i <= n; ++i) s1 ^= A[i];
    ans += (!s1);
    for (int i = 0;i < C; ++i){
        memset(f,0,sizeof(f));
        f[0][0][0] = 1; 
        s1 = 0; s2 = 1;
        bool x = 0,y;
        for (int j = 1;j <= n; ++j){
            y = x; x ^= 1;
            t = (bin[i] - 1) & A[j];
            s1 ^= (A[j] >> (i + 1));
            if ((A[j] >> i) & 1) {
                f[x][0][0] = f[y][1][0] * (t + 1);
                f[x][1][0] = f[y][0][0] * (t + 1);
                f[x][0][1] = f[y][0][1] * bin[i] + f[y][1][1] * (t + 1) + f[y][0][0];
                f[x][1][1] = f[y][1][1] * bin[i] + f[y][0][1] * (t + 1) + f[y][1][0];
            }
            else {
                f[x][0][0] = f[y][0][0] * (t + 1);
                f[x][1][0] = f[y][1][0] * (t + 1);
                f[x][0][1] = f[y][0][1] * (t + 1);
                f[x][1][1] = f[y][1][1] * (t + 1);
            }
        }
        if (!s1) ans += f[x][0][1];
    }
}

int main(){
    init();
    DO_IT();
    cout<<ans - 1;
    return 0;
}
/*
01
10
11
*/

总结:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值