BZOJ - 3687

Description
Xiao Dai began to study set theory, he raised four questions on a number of sets:
1. And a subset of XOR arithmetic sum.
2. And XOR subset and XOR.
3. A subset of arithmetic and arithmetic and.
4. And a subset of the arithmetic and XOR.
So far, Xiao Dai has solved the first three questions, the last remaining issues yet to be resolved, he decided to put
this question to you, the next training team members to achieve.

Top
Input
a first row, an integer n.
The second line, n positive integer representing the 01, a2 .... .

Top
Output
row contains an integer, and represents a subset of all of the exclusive OR and.

Top
the Sample the Input
2
. 1. 3
Top
the Sample the Output
. 6


If we can calculate the number of each program and then we can make out.

Second, we can not think we really do not care about the specific number, only care about parity, because even-exclusive or no effect.

So we seek parity of each. Direct dp complexity is too high, we can optimize the use bitset.

The whole set of each transfer, s = s ^ (1 << x).


AC Code:

#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int N=2e5+10;
int n,res;	bitset<N> bit;
signed main(){
	cin>>n;	bit[0]=1;
	for(int i=1,x;i<=n;i++){
		cin>>x;	bit^=(bit<<x);
	}
	for(int i=0;i<N;i++)	if(bit[i])	res^=i;
	cout<<res;
	return 0;
}
Published 486 original articles · won praise 241 · views 30000 +

Guess you like

Origin blog.csdn.net/weixin_43826249/article/details/104104975