首页 技术 正文
技术 2022年11月19日
0 收藏 980 点赞 2,971 浏览 3569 个字

Problem DescriptionThere 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.

 InputThe 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.
 OutputFor each test case, output the result in one
line. Sample Input231 2 341 2 3 3 Sample Output14

#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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,581
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918