Code : Expected Power
#include <atcoder/modint>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
int mx = 1024;
void solve(vector<int> &a, vector<int> &p) {
int n = a.size();
vector<mint> dp(mx);
dp[0] = 1;
// dp[i] is probability to achieve a xor i.
for (int i = 0; i < n; i++) {
mint px = p[i] / (mint)10000;
vector<mint> ndp(mx);
for (int old = 0; old < mx; old++) {
int nxt = old ^ a[i];
ndp[old] += (1 - px) * dp[old];
ndp[nxt] += px * dp[old];
}
swap(dp, ndp);
}
mint ans = 0;
for (int x = 0; x < mx; x++) {
ans += 1LL * x * x * dp[x];
}
cout << ans.val() << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
for (int zz = 0; zz < t; zz++) {
int n;
cin >> n;
vector<int> a(n), p(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> p[i];
}
solve(a, p);
}
}