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 ;
}

HDU 4901 The Romantic Hero的更多相关文章

  1. HDU 4901 The Romantic Hero (计数DP)

    The Romantic Hero 题目链接: http://acm.hust.edu.cn/vjudge/contest/121349#problem/E Description There is ...

  2. HDU 4901 The Romantic Hero(二维dp)

    题目大意:给你n个数字,然后分成两份,前边的一份里面的元素进行异或,后面的一份里面的元素进行与.分的时候依照给的先后数序取数,后面的里面的全部的元素的下标一定比前面的大.问你有多上种放元素的方法能够使 ...

  3. HDU 4901 The Romantic Hero 题解——S.B.S.

    The Romantic Hero Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Othe ...

  4. 2014多校第四场1005 || HDU 4901 The Romantic Hero (DP)

    题目链接 题意 :给你一个数列,让你从中挑选一些数组成集合S,挑另外一些数组成集合T,要求是S中的每一个数在原序列中的下标要小于T中每一个数在原序列中下标.S中所有数按位异或后的值要与T中所有的数按位 ...

  5. hdu 4901 The Romantic Hero (dp)

    题目链接 题意:给一个数组a,从中选择一些元素,构成两个数组s, t,使s数组里的所有元素异或 等于 t数组里的所有元素 位于,求有多少种构成方式.要求s数组里 的所有的元素的下标 小于 t数组里的所 ...

  6. HDU - 4901 The Romantic Hero(dp)

    https://vjudge.net/problem/HDU-4901 题意 给n个数,构造两个集合,使第一个集合的异或和等于第二个集合的相与和,且要求第一个集合的元素下标都小于第二个集合的元素下标. ...

  7. HDOJ 4901 The Romantic Hero

    DP....扫两次合并 The Romantic Hero Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 ...

  8. HDU4901 The Romantic Hero 计数DP

    2014多校4的1005 题目:http://acm.hdu.edu.cn/showproblem.php?pid=4901 The Romantic Hero Time Limit: 6000/30 ...

  9. HDU 4901(杭电多校训练#3 1005题)The Romantic Hero(DP)

    题目地址:HDU 4901 这题没想到最后竟然可以做出来.. .. 这题用了两次DP,先从前往后求一次异或的.再从后往前求一次与运算的. 各自是 1:求异或的时候,定义二维数组huo[1000][10 ...

随机推荐

  1. 【C#】实现按Windows排序方式排序

    很多人或许都遇到过类似的问题,C#读取的文件列表默认是按ASCII排序的,这样会出现一个问题就是10会排在2的前面. 那么是否可以解决呢,答案是肯定的.虽然这个是很早之前遇到的问题,这次突然想起来,就 ...

  2. 【转】Bresenham快速画直线算法

    一.             算法原理简介: 算法原理的详细描述及部分实现可参考: http://www.cs.helsinki.fi/group/goa/mallinnus/lines/bresen ...

  3. 有一家做BPM的公司叫K2,Gartner和IDC都说好!

    有一家公司被Gartner称为成长最快速的BPMS厂商,被IDC称为破坏性创新者… IDC及Gartner均称K2为成长最快速的商务流程管理套装平台(BPMS)厂商.IDC称K2为“破坏性创新者,在关 ...

  4. http 请求头设置缓存

     nginx不缓存设置 2013-08-15 10:47:39 分类: LINUX 在开发调试web的时候,经常会碰到因浏览器缓存(cache)而经常要去清空缓存或者强制刷新来测试的烦恼,提供下apa ...

  5. win10快捷键大全 win10常用快捷键

    win10快捷键大全大家可以来了解一下,今天小编带来了win10常用快捷键,很多朋友喜欢使用快捷键来操作电脑,那么Windows10系统有哪些新的快捷键呢• 贴靠窗口:Win +左/右> Win ...

  6. 20135316王剑桥 linux第十二周课实验笔记

    第十二章并发编程 1.如果逻辑控制流在时间上重叠,那么它们就是并发的.这种现象,称为并发(concurrency). 2.为了允许服务器同时为大量客户端服务,比较好的方法是:创建并发服务器,为每个客户 ...

  7. Opencv step by step - 视频进度条

    上一个博文只是进行了视频播放,这里加上进度条. 下面是修改好的代码: #include <cv.h> #include <highgui.h> /* * tan@ubuntu: ...

  8. 工作随笔——xshell4安装后应该做的一些事

    xshell4默认支持中文语言 选项→键盘和鼠标:设置快捷键,鼠标按键(可以提高工作效率) 1.选定文本自动复制到剪贴板 选择→将选定的文本自动复制到剪贴板(选上) 2.更高鼠标中间按钮和右键按钮的功 ...

  9. Sqlite3 设置插入触发器

    需求: 数据库中表t_VerifyCsmDetail需要最多保存10W条记录,超出时删除最旧的那一条. 思路:设置插入触发器.插入前先判断表中记录总数,如果大于99999条,则删除最旧的一条记录. 代 ...

  10. IText&Html2canvas js截图 绘制 导出PDF

    Html2canvas JS截图 HTML <div id="divPDF"> 需要截图的区域 </div> JS <script src=" ...