BZOJ 3687: 简单题 bitset

时间:2023-03-08 18:11:24

3687: 简单题

Time Limit: 10 Sec  Memory Limit: 512 MB
[Submit][Status][Discuss]

Description

小呆开始研究集合论了,他提出了关于一个数集四个问题:
1.子集的异或和的算术和。
2.子集的异或和的异或和。
3.子集的算术和的算术和。
4.子集的算术和的异或和。
    目前为止,小呆已经解决了前三个问题,还剩下最后一个问题还没有解决,他决定把
这个问题交给你,未来的集训队队员来实现。

Input

第一行,一个整数n。
第二行,n个正整数,表示01,a2….,。

Output

一行,包含一个整数,表示所有子集和的异或和。

Sample Input

2

1 3

Sample Output

6

HINT

【样例解释】

6=1 异或 3 异或 (1+3)

【数据规模与约定】

ai >0,1<n<1000,∑ai≤2000000。

另外,不保证集合中的数满足互异性,即有可能出现Ai= Aj且i不等于J

Source

bitset+背包dp
*用读优过不去后来换了scanf才过
 #include<bits/stdc++.h>

 using namespace std;

 const int MAXN = ;
const int MAXS = ;
bitset<MAXS> s;
int n; int main() {
scanf("%d", &n);
s.set();
for (int i = ; i <= n; ++i) {
int x;
scanf("%d", &x);
s ^= (s << x);
}
long long ans = ;
for (int i = ; i < MAXS; ++i) {
if (s[i]) {
ans ^= (long long)i;
}
}
cout << ans << "\n";
return ;
}