HDU 4901 The Romantic Hero

来源:互联网 发布:枪火兄弟连2 mac 存档 编辑:程序博客网 时间:2024/06/04 09:31
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
231 2 341 2 3 3
 

Sample Output
1 4
 

Author
WJMZBMR
 

Source
2014 Multi-University Training Contest 4
 

Recommend

We have carefully selected several similar problems for you:  5780 5779 5778 5777 5776 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

WJMZBMR的题~%%%


f[i][j]——前i个数xor得j的方案数

d[i][j]——i~n的数and得j的方案数


^可逆~

另外,什么时候%一定要分清!&一定要初始化!


#include<iostream>#include<cstring>#include<cstdio>using namespace std;const int md=1000000007;int n,ans,a[1025],f[1025][1025],d[1025][1025];int main(){    int t;    scanf("%d",&t);    while(t--)    {        memset(f,0,sizeof(f));        memset(d,0,sizeof(d));        ans=0;f[0][0]=1;        scanf("%d",&n);        for(int i=1;i<=n;++i)            scanf("%d",&a[i]);                for(int i=1;i<=n;i++)            for(int j=0;j<1024;j++)                f[i][j]=(f[i-1][j]+f[i-1][j^a[i]])%md;        //亦或是可逆运算        for(int i=n;i>=1;i--)        {            for(int j=0;j<1024;++j)            {                d[i][j]=d[i+1][j];//继承上一个点的值                d[i][j&a[i]]=(d[i][j&a[i]]+d[i+1][j])%md;            }            d[i][a[i]]+=1;//加上自己        }        for(int i=1;i<=n;i++)            for(int j=0;j<1024;j++)                ans=(ans+(long long)f[i-1][j^a[i]]*d[i+1][j])%md;//枚举断点,累加        printf("%d\n",ans);    }    return 0;}


1 0
原创粉丝点击