链接:http://acm.hdu.edu.cn/showproblem.php?pid=4737
代码原理可看我另一篇文章,基本上一样:http://blog.csdn.net/fallenfall/article/details/11515973
#include<stdio.h>
#include<string.h>
int a[100010];
int main()
{
int n,m,i,j,cas,k;
scanf("%d",&cas);
for(k=1;k<=cas;k++)
{
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
int cnt=0,ans;
for(i=0;i<n;i++)
{
ans=a[i];
for(j=i;j<n;j++)
if((ans|a[j])>=m)
break;
else
{
cnt++;
ans=ans|a[j];
}
}
printf("Case #%d: %d\n",k,cnt);
}
return 0;
}