Problem 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
#include<cstdio>
#include<cstring> typedef __int64 LL;
#define mod 1000000007
const int MAXN = ;
const int MAXA = ;
int dp1[MAXN][MAXA], dp2[MAXN][MAXA], dp3[MAXN][MAXA];
int a[MAXN]; int main()
{
int T, n, i, j, t;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
for(i = ; i < n; i++)
scanf("%d",&a[i]);
memset(dp1, , sizeof(dp1));
memset(dp2, , sizeof(dp2));
memset(dp3, , sizeof(dp3));
dp1[][a[]] = ;
for(i = ; i < n - ; i++) {
dp1[i][a[i]]++; //单独一个元素构成一个集合
for(j = ; j < MAXA; j++) {
if(dp1[i-][j]) {
dp1[i][j] += dp1[i-][j]; //不添加第i个元素进行异或,继承之前算好的
dp1[i][j] %= mod; t = j ^ a[i]; //添加第i个元素进行异或
dp1[i][t] += dp1[i-][j];
dp1[i][t] %= mod;
}
}
}
dp2[n-][a[n-]] = ;
dp3[n-][a[n-]] = ;
for(i = n-; i > ; i--) {
dp2[i][a[i]]++;
dp3[i][a[i]]++; //单独一个元素构成一个集合
for(j = ; j < MAXA; j++) {
if(dp2[i+][j]) {
dp2[i][j] += dp2[i+][j]; //不添加第i个元素进行按位与
dp2[i][j] %= mod; t = j & a[i]; //添加第i个元素进行按位与
dp2[i][t] += dp2[i+][j];
dp2[i][t] %= mod; dp3[i][t] += dp2[i+][j]; //添加第i个元素进行按位与
dp3[i][t] %= mod;
}
}
}
int ans = ;
for(i = ; i < n - ; i++) {
for(j = ; j < MAXA; j++) {
if(dp1[i][j] && dp3[i+][j]) {
ans += (LL(dp1[i][j]) * dp3[i+][j] % mod);
ans %= mod;
}
}
}
printf("%d\n", ans);
}
return ;
}
 #include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=1e3+;
const int maxm=*;
const int mod=1e9+;
int n,a[maxn];
int dp[maxn][maxm][],dps[maxn][maxm][];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
int maxi=;
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
memset(dp,,sizeof(dp));
memset(dps,,sizeof(dps));
for(int i=;i<=n;i++)
{
dp[i][a[i]][]=;
dps[i][a[i]][]=;
for(int j=;j<maxm;j++)
if(dp[i-][j][])
{
dp[i][j][]=(dp[i][j][]+dp[i-][j][])%mod;
dp[i][j^a[i]][]=(dp[i][j^a[i]][]+dp[i-][j][])%mod;
dps[i][j^a[i]][]=(dps[i][j^a[i]][]+dp[i-][j][])%mod;
}
}
for(int i=n;i>=;i--)
{
dp[i][a[i]][]=;
for(int j=;j<maxm;j++)
if(dp[i+][j][])
{
dp[i][j][]=(dp[i][j][]+dp[i+][j][])%mod;
dp[i][j&a[i]][]=(dp[i][j&a[i]][]+dp[i+][j][])%mod;
}
}
long long ans=;
for(int i=;i<n;i++)
for(int j=;j<maxm;j++)
if(dps[i][j][])
ans=(ans+(long long)dps[i][j][]*(long long)dp[i+][j][])%mod;
printf("%I64d\n",ans);
}
return ;
}

The Romantic Hero的更多相关文章

  1. HDU 4901 The Romantic Hero

    The Romantic Hero Time Limit: 3000MS   Memory Limit: 131072KB   64bit IO Format: %I64d & %I64u D ...

  2. HDU4901 The Romantic Hero 计数DP

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

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

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

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

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

  5. 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 ...

  6. HDOJ 4901 The Romantic Hero

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

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

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

  8. hdu 4901 The Romantic Hero (dp)

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

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

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

随机推荐

  1. 数往知来C#面向对象准备〈二〉

    面向对象(OOP→Object-Oriented Programming) 1.什么是面向对象? 一种分析问题的方式. 2.面向对象三大特征: 封装(隐蔽代码实现/复用/修改方便).继承.多态. 3. ...

  2. 自学hadoop(三)

    1) 关于hadoop在eclipse插件.经过自己的摸爬滚打.总结一下三条.     a) 2.0或者0.23.0吧 google比较方便.其他的可以自己编译.(这个我不敢保证.我本地环境事2.1. ...

  3. 一起刷LeetCode1-Two Sum

    感觉有必要重新刷刷题了,为以后找工作做做准备,选择LeetCode+topcoder上的Data Science Tutorials, 争取每天晚上10:00开始刷一道,复习一下相关知识点. ---- ...

  4. [算法] 希尔排序 Shell Sort

    希尔排序(Shell Sort)是插入排序的一种,它是针对直接插入排序算法的改进.该方法又称缩小增量排序,因DL.Shell于1959年提出而得名. 希尔排序实质上是一种分组插入方法.它的基本思想是: ...

  5. 我是怎么发现并解决项目页面渲染效率问题的(IE调试工具探查器的使用)

    #我是怎么发现并解决项目页面渲染效率问题的(IE调试工具探查器的使用) ##背景 之前的项目中,有很多的登记页面,一般都有100-200甚至更加多的字段,而且还涉及到字典.日期及其他效果的显示,载入时 ...

  6. J2EE开发常用开源框架技术(转)

    1持久层:1)Hibernate这个不用介绍了,用的很频繁,用的比较多的是映射,包括继承映射和父子表映射对 于DAO在这里介绍个在它基础上开发的包bba96,目前最新版本是bba96 2.0它对Hib ...

  7. Visual Studio 2013智能提示失效解决办法

    各种解决VS2013智能提示失效办法: 1.重置所有设置    工具->导入导出设置->重置所有设置 2.智能提示开关: 工具->选项->文本编辑器->C#->常规 ...

  8. Shell统计报表表格生成

    基本需求 分析完数据后,一般需要将数据以附件的形式发送处理,这个已经在<>中有介绍,如何 用Python实现附件的发送. 但不是所有人都关心附件的内容,一般邮件中需要有些概要的信息,如附件 ...

  9. Python 3.2: 使用pymysql连接Mysql

    在python 3.2 中连接MYSQL的方式有很多种,例如使用mysqldb,pymysql.本文主要介绍使用Pymysql连接MYSQL的步骤 1        安装pymysql ·       ...

  10. 为什么要坚持用ASP.NET MVC!(②)

    尽管ASP.NET MVC架构和Web Form架构区别很大,但是还是有很多共同之处.毕竟它们都是以ASP.NET API与.NET框架为基础构建的.比较一下ASP.NET MVC和Web Form框 ...