bzoj 3687: 简单题 bitset

题目链接

bzoj3687: 简单题

题解

子集的和的异或和。
f[i]表示和为i的出现的次数
bitset优化一下背包

代码

#include<cstdio> 
#include<bitset> 
#include<cstring> 
#include<algorithm> 
#define LL long long 
#define gc getchar() 
#define pc putchar
inline int read() { 
    int x = 0,f = 1; 
    char c = gc; 
    while(c < '0' || c > '9' )c = gc; 
    while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = gc; 
    return x * f ;
} 
void print(int x) {
     if(x >= 10) print(x / 10); 
     pc(x % 10 + '0'); 
} 
int n; 
const int maxn = 2000000; 
std::bitset<maxn>s; 
int main() { 
    n = read(); 
    s[0] = 1; 
    int sum = 0; 
    for(int a,i = 1;i <= n;++ i) { 
        a = read(); 
        sum += a; 
        s ^= (s << a);    
    } 
    int ans = 0; 
    for(int i = 1;i <= sum;++ i) 
        if(s[i]) ans ^= i; 
    print(ans); 
    return 0; 
} 

转载于:https://www.cnblogs.com/sssy/p/9769405.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值