题意:
给你一个数组R,包含N个元素,求有多少满足条件的序列A使得
0 ≤ A[i] ≤ R[i]
A[0]+A[1]+…+A[N-1]=A[0] or A[1]… or A[N-1]
思路:等式成立的前提是如果某一二进制位上存在1,那必定是由N个元素中某一个提供,除这个数外的其他数,这一位上只能是0。
#include<bits/stdc++.h>
#define f(i,a,b) for( int i=a;i<=b;++i)
#define ff(i,a,b) for( int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1e9 + 9;
const ll mod2 = 998244353;
const int inf = 0x3f3f3f3f;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
inline int in() { char ch = getchar();int x = 0, f = 1;while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }return x * f; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const int N = 5005;
ll f[62][1 << 11];
//f[每一位][每一个数的是否还收限制]
ll r[11];
int n;
ll dfs(int pos,int now)
{
if (pos < 0)return 1;
if (f[pos][now] != -1)return f[pos][now];
//当前位要,那么从有这一位或者不受限制的数中选一个(对于其他数有这一位的解除限制)
//当前位不要,所有数中有这一位的全部解除限制
ll res = 0;
f(i, 0, n - 1)
{
int tmp = now;
if ((r[i] >> pos & 1) || !(now >> i & 1))
{
f(j, 0, n - 1)
{
if (j == i)continue;
if ((r[j]>>pos&1)&&(tmp >> j & 1))tmp ^= (1 << j);
}
res = (res + dfs(pos - 1, tmp))%mod;
}
}
int tmp = now;
f(i, 0, n - 1)
if ((r[i] >> pos & 1) && (tmp >>i& 1))tmp ^= (1 << i);
res=(res+dfs(pos - 1, tmp))%mod;
return f[pos][now] = res;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
memset(f, -1, sizeof f);
n = in();
f(i, 0, n-1)scanf("%lld", &r[i]);
cout << dfs(61, (1 << n) - 1) << endl;
return 0;
}