1. 程式人生 > >bzoj 3687 簡單題——bitset

bzoj 3687 簡單題——bitset

sdn pac tails article names color n) ring mes

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

關於 bitset :https://blog.csdn.net/snowy_smile/article/details/79120063

      https://blog.csdn.net/liushu1231/article/details/8844631

不知為何,上面的可以 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; }

bzoj 3687 簡單題——bitset