^m
路漫漫

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才过
 
 1 #include<bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 const int MAXN = 1100;
 6 const int MAXS = 2100000;
 7 bitset<MAXS> s;
 8 int n;
 9 
10 int main() {
11     scanf("%d", &n);
12     s.set(0);
13     for (int i = 1; i <= n; ++i) {
14         int x;
15         scanf("%d", &x);
16         s ^= (s << x);
17     }
18     long long ans = 0;
19     for (int i = 0; i < MAXS; ++i) {
20         if (s[i]) {
21             ans ^= (long long)i;
22         }
23     }
24     cout << ans << "\n";
25     return 0;
26 } 
View Code

 

posted on 2018-05-26 12:35  ^m  阅读(128)  评论(0编辑  收藏  举报