简单题 HYSBZ - 3687

题目链接

用bitset计算出所有的子集情况。

从右向左数的第几位就代表是几;

 1 #include<cstring>
 2 #include<cstdlib>
 3 #include<algorithm>
 4 #include<cmath>
 5 #include<bitset>
 6 using namespace std;
 7 int n,x,sum,ans;
 8 bitset<2000000> a;
 9 int main()
10 {
11     scanf("%d",&n);
12     a[0]=1;
13     while(n--)
14     {
15         scanf("%d",&x);
16         sum+=x;
17         a^=(a<<x);
18     }
19     for(int i=1;i<=sum;i++)
20         if(a[i])ans^=i;
21     printf("%d",ans);
22     return 0;
23 }

 

posted @ 2020-02-29 20:10  jvruodejxt  阅读(71)  评论(0编辑  收藏  举报

Contact with me