http://acm.hdu.edu.cn/showproblem.php?pid=3929
Lucas定理
代码
import java.util.*;
public class Main {
static Scanner in = new Scanner(System.in);
static long find(long[] a) {
if(a.length==1)
return 1l<<Long.bitCount(a[0]);
long[] b = new long[a.length-1];
for(int i=0; i<b.length; ++i)
b[i] = a[i+1];
long ans = find(b);
for(int i=0; i<b.length; ++i)
b[i] &= a[0];
ans += (1l<<Long.bitCount(a[0]))-2*find(b);
return ans;
}
public static void main(String[] args) {
final int T=in.nextInt();
for(int cas=1; cas<=T; ++cas) {
int N=in.nextInt();
long[] arr = new long[N];
for(int i=0; i<N; ++i)
arr[i] = in.nextLong();
System.out.println("Case #"+cas+": "+find(arr));
}
}
}