Time Limit: 3000MS   Memory Limit: 131072KB   64bit IO Format: %I64d & %I64u

Description

开头背景介绍无用

There is an old country and the king fell in love with a devil. The devil always asks the king to do some crazy things. Although the king used to be wise and beloved by his people. Now he is just like a boy in love and can’t refuse any request from the devil. Also, this devil is looking like a very cute Loli.

You may wonder why this country has such an interesting tradition? It has a very long story, but I won't tell you :).

Let us continue, the party princess's knight win the algorithm contest. When the devil hears about that, she decided to take some action.

But before that, there is another party arose recently, the 'MengMengDa' party, everyone in this party feel everything is 'MengMengDa' and acts like a 'MengMengDa' guy.

While they are very pleased about that, it brings many people in this kingdom troubles. So they decided to stop them.

 
以下才是题目

Our hero z*p come again, actually he is very good at Algorithm contest, so he invites the leader of the 'MengMengda' party xiaod*o to compete in an algorithm contest.

As z*p is both handsome and talkative, he has many girl friends to deal with, on the contest day, he find he has 3 dating to complete and have no time to compete, so he let you to solve the problems for him.

And the easiest problem in this contest is like that:

There is n number a_1,a_2,...,a_n on the line. You can choose two set S(a_s1,a_s2,..,a_sk) and T(a_t1,a_t2,...,a_tm). Each element in S should be at the left of every element in T.(si < tj for all i,j). S and T shouldn't be empty.

And what we want is the bitwise XOR of each element in S is equal to the bitwise AND of each element in T.

How many ways are there to choose such two sets? You should output the result modulo 10^9+7.

 

Input

The first line contains an integer T, denoting the number of the test cases. 
For each test case, the first line contains a integers n. 
The next line contains n integers a_1,a_2,...,a_n which are separated by a single space.

n<=10^3, 0 <= a_i <1024, T<=20.

 

Output

For each test case, output the result in one line.
 

Sample Input

2
3
1 2 3
4
1 2 3 3
 

Sample Output

1
4
 

Source

2014 Multi-University Training Contest 4

动规。先预处理好XOR集合和AND集合在每个位置的最优解,之后枚举断点,左边是XOR集合,右边是AND集合,累加答案。

 #include<algorithm>
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int q=;
const int mxn=;
int n,k;
int a[mxn];
int f[mxn][mxn],t[mxn][mxn];
int main(){
int T;
scanf("%d",&T);
while(T--){
memset(f,,sizeof(f));
memset(t,,sizeof(t));
scanf("%d",&n);
int i,j;
for(i=;i<=n;i++)scanf("%d",&a[i]);
//xor
f[][]=; //边界
for(i=;i<=n;i++){
for(j=;j<;j++){
f[i][j]=(f[i-][j]+f[i-][j^a[i]])%q;
}
}
//and
for(i=;i<=n;i++)t[i][a[i]]=;
for(i=n;i>=;i--){
for(j=;j<;j++){
t[i][j]=t[i+][j];//不选
}
for(j=;j<;j++){//选
t[i][j&a[i]]=(t[i][j&a[i]]+t[i+][j])%q;
}
t[i][a[i]]=(t[i][a[i]]+)%q;
}
//
int ans=;
for(i=;i<n;i++){
for(j=;j<;j++)
ans=(ans+(long long)t[i+][j]*f[i-][j^a[i]])%q;//累加结果
}
printf("%d\n",ans);
}
return ;
}

最新文章

  1. 自定义AlertDialog控件的使用(AndroidStudio)
  2. php常用数组函数小结
  3. 【Effective Java】1、静态工厂的方式代替构造函数
  4. curl 命令行应用
  5. Azure linux centos 默认登陆账号是什么?
  6. Spring-boot 配置Aop获取controller里的request中的参数以及其返回值
  7. 【转】android开发中关于模拟器emulation的常见问题
  8. Managing Data in Containers
  9. Java对文件的16进制读取和操作
  10. 【WebStorm】前端工具开发利器webstrom专篇...更新中
  11. Java 八大类型、String和 StringBuffer
  12. Git和Github使用
  13. 网络基础之IP地址与子网划分
  14. 问题:编译eshoponcontainers失败,提示error:invalid reference format
  15. 侯哥的Python分享
  16. Mqtt使用教程,简介
  17. memset与fill的区别
  18. HDU 2841-Visible Trees 【容斥】
  19. python 全栈开发,Day47(行级块级标签,高级选择器,属性选择器,伪类选择器,伪元素选择器,css的继承性和层叠性,层叠性权重相同处理,盒模型,padding,border,margin)
  20. centos7上编译安装mysql5.6

热门文章

  1. 用bower命令创建项目
  2. $watch方法
  3. “display:block-inline形式的Span或Div中添加文字后,导致Span或Div排版掉落、错位”的原因及解决方法
  4. Android应用开发中如何使用隐藏API(转)
  5. 【Asp.Net】Asp.Net CommandName作用
  6. WorldWind源码剖析系列:WorldWind如何确定与视点相关的地形数据的LOD层级与范围
  7. Ubuntu 14.04 下安装google的浏览器——Chrome
  8. [CareerCup] 2.6 Linked List Cycle 单链表中的环
  9. [C++] 如何查看DLL有哪些函数
  10. Linux第三次实验报告