链接:https://ac.nowcoder.com/acm/problem/21336
来源:牛客网
给你一个数组R,包含N个元素,求有多少满足条件的序列A使得
0 ≤ A[i] ≤ R[i]
A[0]+A[1]+...+A[N-1]=A[0] or A[1]... or A[N-1]
输出答案对1e9+9取模
第一行输入一个整数N (2 ≤ N ≤ 10)
第二行输入N个整数 R[i] (1 ≤ R[i] ≤ 1e18)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e7+1000;
const ll mod=1e9+9;
ll a[20],dp[100][2000];
int n;
ll dfs(ll d,int st) {
if(d<0) return 1;
ll ans=dp[d][st];
if(ans!=-1) return ans;
int temp=st;
for(int i=0;i<n;i++)
if(a[i]>>d&1) temp|=1<<i;
ans=dfs(d-1,temp);
for(int i=0;i<n;i++) {
if(st>>i&1) ans=(ans+dfs(d-1,temp))%mod;
else if(a[i]>>d&1)
ans=(ans+dfs(d-1,temp^(1<<i)))%mod;
}
return dp[d][st]=ans;
}
int main() {
cin>>n;
memset(dp,-1,sizeof dp);
for(int i=0;i<n;i++) cin>>a[i];
cout<<dfs(60,0);
}
来源:https://www.cnblogs.com/bxd123/p/12234360.html
