其他分享
首页 > 其他分享> > bzoj 3687 简单题——bitset

bzoj 3687 简单题——bitset

作者:互联网

题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3687

关于 bitset :https://blog.csdn.net/snowy_smile/article/details/79120063

不知为何,上面的可以 A ,下面的会 WA 。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
using namespace std;
const int M=2e6+5;
int n,s,ans;
bitset<M> dp;
int main()
{
    scanf("%d",&n); dp[0]=1;
    for(int i=1,d;i<=n;i++)
    {
        scanf("%d",&d);
        dp^=(dp<<d); s+=d;
    }
    for(int i=1;i<=s;i++)if(dp[i])ans^=i;
    printf("%d\n",ans);
    return 0;
}
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
using namespace std;
const int N=1005,M=2e6+5;
int n,a[N];
bitset<M> dp;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    dp[0]=1; int s=0;
    for(int i=1;i<=n;i++)
        dp^=(dp<<a[i]),s+=a[i];
    int ans=0;
    for(int i=1;i<=s;i++)if(dp[i])ans^=i;
    printf("%d\n",ans);
    return 0;
}

 

标签:int,2e6,3687,bitset,using,include,dp,bzoj
来源: https://www.cnblogs.com/Narh/p/10385736.html