bzoj 3687: 简单题

2333,昨天模拟赛第一题死都想不出怎么优化tarjan,然而正解是一个kora***什么什么的东西,就是正反两遍dfs,然后这个算法求强联通分量的话,是可以用bitset来优化一下的(只考虑点)。

 

 

我的天,我在说什么,,,,

这个题暴力是用类似背包的东西DP转移一下,然后我们有了bitset,可以直接对整个数组操作!!这些都是浮云(因为这个题的sum不大,可以把把存在的sum用bitset里的a[sum]=1来表示) 

 1 #include<bits/stdc++.h>
 2 #define N 1000005
 3 using namespace std;
 4 bitset< N<<1 > a;
 5 int n,sum,ans;
 6 int main()
 7 {
 8     scanf("%d",&n);
 9     a[0]=1;
10     while (n--)
11     {
12         int x; scanf("%d",&x); sum+=x;
13         a^=(a<<x);
14     }
15     for (int i=1; i<=sum; i++)
16         if (a[i]) ans^=i;
17     printf("%d",ans);
18     return 0;
19 }

 

posted @ 2017-03-13 21:27  ws_ccd  阅读(202)  评论(0编辑  收藏  举报