BZOJ 3687: 简单题 动态规划+bitset

数字很多,但是由于总和不超过 $2\times 10^6$,所以最多只能凑出来 $2\times 10^6$ 种算术和.  

由于这里是对算是和取异或,所以我们只需关注每种算术和出现次数的奇偶.   

由于奇奇 $\Rightarrow$ 偶,奇偶 $\Rightarrow$ 奇,偶偶 $\Rightarrow$ 偶,所以直接用 bitset 来加速就好了

#include <cstdio>
#include <bitset> 
#include <algorithm>
#define N 2000007 
#define ll long long 
#define setIO(s) freopen(s".in","r",stdin)  
using namespace std;
bitset<N>f;  
int main() 
{   
    // setIO("input");
    int i,j,m=0,n,x;  
    f[0]=1;   
    scanf("%d",&n); 
    for(i=1;i<=n;++i) scanf("%d",&x),f^=(f<<x),m+=x;  
    int ans=0;
    for(i=1;i<=m;++i) if(f[i]) ans^=i; 
    printf("%d\n",ans); 
    return 0; 
}

  

posted @ 2020-01-02 22:27  EM-LGH  阅读(140)  评论(0编辑  收藏  举报