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. android开发的学习路线(转)

    第一阶段:Java面向对象编程 1.Java基本数据类型与表达式,分支循环. 2.String和StringBuffer的使用.正则表达式. 3.面向对象的抽象,封装,继承,多态,类与对象,对象初始化 ...

  2. C#调用dll(C++(Win32))时的类型转换总结(转)

    http://www.cnblogs.com/lidabo/archive/2012/06/05/2536737.html     C++(Win 32) C# char** 作为输入参数转为char ...

  3. Android 4.4 音量调节流程分析(二)

    之前在Android 4.4 音量调节流程分析(一)里已经有简单的分析音量控制的流程,今天想接着继续分析下音量大小计算的方法.对于任一播放文件而言其本身都有着固定大小的音量Volume_Max,而在A ...

  4. Adress

    流水账的写法:因为不想让亲爱的你只看开头就关掉了我辛苦的劳作.流水账的好处是:便于逻辑的理解 http://software.intel.com/zh-cn/blogs/2014/01/20/cent ...

  5. SpringMVC学习笔记

    1.严格实现MVC设计思想的框架,严格分层,减少耦合: 2.组件(红色必需) 2.1 DispatcherServlet 前端控制器 2.2 Controller 业务控制器 2.3 Handler ...

  6. HDU 4911 Inversion (逆序数 归并排序)

    Inversion 题目链接: http://acm.hust.edu.cn/vjudge/contest/121349#problem/A Description bobo has a sequen ...

  7. codeforces 622A Infinite Sequence

    A. Infinite Sequence time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. My97DatePicker时间控件使用说明

    常规调用: <input id="date01" type="text" onClick="WdatePicker()"/> & ...

  9. jquery ajax请求后台 的简单例子

    jQuery.ajax(url,[settings]) 概述 通过 HTTP 请求加载远程数据. jQuery 底层 AJAX 实现.简单易用的高层实现见 $.get, $.post 等.$.ajax ...

  10. java对cookie的操作_01

    /** * 读取所有cookie * 注意二.从客户端读取Cookie时,包括maxAge在内的其他属性都是不可读的,也不会被提交.浏览器提交Cookie时只会提交name与value属性.maxAg ...