-
Notifications
You must be signed in to change notification settings - Fork 12
/
BADXOR.cpp
72 lines (63 loc) · 1.24 KB
/
BADXOR.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
AUTHOR: Akhilesh Anandh
Solution for "Bad XOR" (www.spoj.com/problems/BADXOR)
Algorithm: DP
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;
#define EPS 0.0000001
typedef long long LL;
#define gc getchar_unlocked
int read_int(){
register int x = 0, c = gc();
int sign = 1;
while(c!='-' && (c<48 || c>57) ) c = gc();
if(c=='-')
sign = -1, c = gc();
while(c>=48 && c<=57)
x = (x<<1) + (x<<3) + c - 48, c = gc();
return sign*x;
}
int dp[1025][1025];
//dp[i][j] -> ways to get xor value of j, using
// first i elements of the array A
int A[1025], B[1025];
bool inB[1025];
#define mod 100000007
int main()
{
int t,n,m,i,j,c=1;
for(t=read_int();c<=t;c++){
n = read_int();
m = read_int();
for(i=0;i<n;i++)
A[i] = read_int();
memset(inB,0,sizeof(inB));
for(j=0;j<m;j++){
B[j] = read_int();
inB[B[j]] = true;
}
memset(dp,0,sizeof(dp));
dp[0][0] = 1;
for(i=1;i<=n;i++){
int a = A[i-1];
for(j=0;j<1024;j++){
dp[i][j] = dp[i-1][j] + dp[i-1][j^a];
if(dp[i][j]>=mod)
dp[i][j] -= mod;
}
}
int ans = 0;
for(j=0;j<1024;j++){
if(!inB[j]){
ans += dp[n][j];
if(ans>=mod) ans -= mod;
}
}
printf("Case %d: %d\n",c,ans);
}
return 0;
}