hdu4901 the Romantic Hero count DP

Source: Internet
Author: User

The Romantic Hero

Time limit:6000/3000 MS (java/others) Memory limit:131072/131072 K (java/others)
Total submission (s): 1797 Accepted Submission (s): 762


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 is wise and beloved by his people. Now he's just like a boy in love and can ' t refuse any request from the devil. Also, this devil was looking like a very cute Loli.

Wonder why is this country have such an interesting tradition? It has a very long stories, but I won ' t tell you:).

Let us continue, the party princess ' s Knight win the algorithm contest. When the devil hears on that, she decided to take some action.

But before that, there was another party arose recently, the ' Mengmengda ' Party, everyone in this party feel everything is ' Mengmengda ' and acts like a ' Mengmengda ' guy.

While they is 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 was 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 had many girl friends to deal with, on the contest day, he find he had 3 dating To complete and has no time to compete, so he-let-solve the problems for him.

And the easiest problem in this contest are like that:

There is n number a_1,a_2,..., A_n on the line. You can choose the set S (A_s1,a_s2,.., A_sk) and T (A_t1,a_t2,..., a_tm). Each element in S should is 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 are the bitwise XOR of each element in S are equal to the bitwise and of each element in T.

How many ways is there to choose such? You should output the result modulo 10^9+7.

Inputthe first line contains an integer T, denoting the number of the 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 is 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 OUTPUT1 4

Count DP, recently seems to have seen a lot of Tao, has not, and today a good look

Test instructions

Divides the series into two parts, the left to take some number, the right to take some number, the left to take out the number of different or, the right to take out the number of the bitwise and, see how many kinds of extraction

4 DP Arrays

A1[I][J] Number of first I, number of I must be taken, XOR and how many cases are J?

A0[I][J] Number of previous I, number of I do not take, XOR and how many cases for J

B1[I][J] from the back to the I, the number of number I must take, the bitwise and how many cases of J

B0[I][J] from the back to the number I, the number of I do not take, bitwise and how many cases for J

The answer is ANS+=A1[I][J]*B0[I][J];

1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <iostream>5 using namespacestd;6 Long Longa1[1001][1025],a0[1001][1025],b0[1001][1025],b1[1001][1025],mod=1000000007;7 ints[1001];8 intn,t;9 intMain ()Ten { OneCin>>T; A      while(t--) -     { -memset (A1,0,sizeof(A1)); theMemset (A0,0,sizeof(a0)); -memset (B0,0,sizeof(B0)); -Memset (B1,0,sizeof(B1)); -Cin>>N; +          for(intI=1; i<=n;i++) -         { +scanf"%d",&s[i]); Aa1[i][s[i]]=1; at              for(intj=0;j<1024x768; j + +) -             { -A1[i][j^s[i]]= (a1[i][j^s[i]]+a1[i-1][j]+a0[i-1][J])%MoD; -A0[i][j]= (a0[i][j]+a0[i-1][j]+a1[i-1][J])%MoD; -             } -         } in          for(inti=n;i>=1; i--) -         { tob1[i][s[i]]=1; +              for(intj=0;j<1024x768; j + +) -             { theB1[i][j&s[i]]= (b1[i][j&s[i]]+b1[i+1][j]+b0[i+1][J])%MoD; *B0[i][j]= (b0[i][j]+b0[i+1][j]+b1[i+1][J])%MoD; $             }Panax Notoginseng         } -         Long Longans=0; the          for(intI=1; i<n;i++) +         { A              for(intj=0;j<1024x768; j + +) the             { +                 if(a1[i][j]&&B0[i][j]) -                 { $Ans= (Ans+a1[i][j]*b0[i][j])%MoD; $                 } -             } -         } thecout<<ans<<Endl; -     }Wuyi     return 0; the}

hdu4901 the Romantic Hero count DP

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.