BADXOR - Bad XOR
#include <iostream>
#include <cstring>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i, n) for(int i = 1; i <= n; i++)
using namespace std;
typedef long long int ll;
const int maxLimit = 100000007;
ll dp[1005][1024];
//dp[i][j] = number of ways of making value j with first i elements
int main()
{
int t, a, b;
int arr1[1001];
bool arr2[1025];
cin >> t;
REP1(k, t)
{
memset(dp, 0, sizeof(dp));
memset(arr2, false, sizeof(arr2));
cin >> a >> b;
REP(i, a)
{
cin >> arr1[i];
}
REP(i, b)
{
int temp;
cin >> temp;
arr2[temp] = true;
}
dp[0][0] = 1;
REP1(i, a)
{
REP(j, 1024)
{
dp[i][j] = dp[i - 1][j] + dp[i - 1][j ^ arr1[i - 1]];
if(dp[i][j] >= maxLimit)
dp[i][j] -= maxLimit;
}
}
ll total = 0; // number of subset
REP(i, 1024)
{
if(!arr2[i])
{
total += dp[a][i];
if(total >= maxLimit)
total -= maxLimit;
}
}
cout << "Case " << k << ": " << total << endl;
}
return 0;
}
can somesone post the solution of BADXOR using topdown approach
ReplyDelete