HDOJ 4901 The Romantic Hero

Source: Internet
Author: User

HDOJ 4901 The Romantic Hero


DP... scan and combine

The Romantic Hero Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission (s): 547 Accepted Submission (s): 217


Problem DescriptionThere is an old country and the king fell in love with a dedevil. the dedevil 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 dedevil. also, this dedevil 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 dedevil 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 should 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 'mengda' party xiaod * o to compete in an algorithm contest.

As z * p is both handsome and talkative, he has cute 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 shoshould 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 shoshould 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 Input
231 2 341 2 3 3

Sample Output
1 4

AuthorWJMZBMR
Source2014 Multi-University Training Contest 4


#include 
 
  #include 
  
   #include 
   
    #include using namespace std;typedef long long int LL;const LL mod=(1e9+7);int n,a[1100];LL dl[1100][2100],sdl[1100][2100];LL dr[1100][2100],sdr[1100][2100];void init(){    memset(dl,0,sizeof(dl));    memset(sdl,0,sizeof(sdl));    memset(dr,0,sizeof(dr));    memset(sdr,0,sizeof(sdr));}int main(){    int T_T;    scanf("%d",&T_T);    while(T_T--)    {        scanf("%d",&n);        init();        for(int i=1;i<=n;i++)            scanf("%d",a+i);        dl[1][a[1]]=sdl[1][a[1]]=1LL;        for(int i=2;i<=n;i++)        {            for(int j=0;j<2048;j++)            {                dl[i][a[i]^j]=(dl[i][a[i]^j]+sdl[i-1][j])%mod;            }            dl[i][a[i]]=(dl[i][a[i]]+1)%mod;            for(int j=0;j<2048;j++)                sdl[i][j]=(sdl[i-1][j]+dl[i][j])%mod;        }        dr[n][a[n]]=sdr[n][a[n]]=1LL;        for(int i=n-1;i>=1;i--)        {            for(int j=0;j<2048;j++)            {                dr[i][j&a[i]]=(dr[i][j&a[i]]+sdr[i+1][j])%mod;            }            dr[i][a[i]]=(dr[i][a[i]]+1)%mod;            for(int j=0;j<2048;j++)                sdr[i][j]=(sdr[i+1][j]+dr[i][j])%mod;        }        LL ret=0;        for(int i=1;i
    
     


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.