HDU--4901 -- the romantic hero

Source: Internet
Author: User
Tags new set

The romantic hero Time Limit: 6000/3000 MS (Java/others) memory limit: 131072/131072 K (Java/others) total submission (s): 1112 accepted submission (s): 459

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

Question: divide the number of this series into two parts. All the numbers in X must be smaller than those in B. In these allocation schemes, all the numbers in X are "exclusive" and the values in Y are equal to the total number in Y. The number in X and Y cannot be blank.


In practice, DP uses the split line method to divide the series into two sections, then, X [I] [J] is used to represent the total number of solutions for a set of numbers that can be composed of I numbers from the beginning, Y [I] [J] is similar to X [I] [J], but the difference is that when the subscript is greater than J, all the schemes in X [J] exist in X [I], while in Y [I], only the number of schemes for "and" operation with the I and number are recorded, this won't be repeated, Because I matched X [I-1] [J] In Y [I] [J, X [I-1] [J] Any X [I1] [J1] solution that moves the split line left is available in X [I] [J, so I only match once at this time.

For example:

4

1 2 3 3

X [1] = {1}

X [2] = {1, 2, 1 ^ 2}

X [3] = {, ^ 1 ^ 2 ^ 3}

X [4] does not need to be calculated, because if the fourth digit is used, the column Y is null, which violates the condition.


Y [4] = {3}

Y [3] = {3, 3 & 3} // here 3 is 3 of the third digit, the third of the fourth digit appears in Y [4] and matches X [3, Y [3] is the solution obtained from the last number to the third number and the third number 3.

Y [2] = {2, 2 & 3, 2 & 3 & 3}


When Y [4] matches X [3], Y [4] matches X [2], Y [4] matches X [1, after all, X [3] contains all the solutions of X [2] and X [1 ].

Then, the Y [4] scheme does not need to be passed to Y [3], otherwise it will be matched with X [2], X [1], so it will be repeated, however, you still need to save the record, because any number above can form a new set with it.


Who will believe that I have been doing this for a day? When I first wanted to understand the meaning of the question, I had to find a blog with only three results. Now it's just a few pages, and I 've been wa in a code, but I saw a code exactly the same as myself in my blog. You should know that in this case, I would suspect that he is also wa. As a result, his AC didn't tell me why after two hours, let others see the results... I wrote "1024" to "1014". I wiped your sister's eggs.


# Include <iostream> # include <cstdio> # include <cstring> # define ll _ int64 # define mod 1000000007 using namespace STD; ll X [1111] [2222], Y [1111] [2222]; // X: Left side of the split line, Y: Right side of the split line, for example, X [I] [J] indicates that the split line exists in the middle of the number I and the number I + 1, or the result is the number of J schemes int main (void) {int t, n, I, J, K, L; int s [1010]; scanf ("% d", & T ); while (t -- & scanf ("% d", & N) {memset (x, 0, sizeof (x); memset (Y, 0, sizeof (y); for (I = 1; I <= N; I ++) {scanf ("% d", & S [I]); X [I] [s [I] = 1; // a single element is also considered as a solution for (j = 0; j <1024; j ++) // traverse all values, returns all of the preceding split-line schemes to the current split-Line Scheme. {x [I] [J] = (X [I] [J] + X [I-1] [J]) % MOD; // number of transfer schemes, that is, X [I] contains all X [I-j] (j> 0) causes of number of schemes in X [I] [J ^ s [I] = (X [I] [J ^ s [I] + X [I-1] [J]) % MOD; // Save the new scheme that these schemes are different or the current one is worth it} ll sum = 0; for (I = N; I> 1; I --) {Y [I] [s [I] = 1; // a single element is also considered as a solution for (j = 0; j <1024; j ++) // traverse all values if (Y [I + 1] [J]) // if the number of solutions with this value of J exists in Y [I] [J & S [I] = (Y [I] [J & S [I] + Y [I + 1] [J]) % MOD; // obtain the new scheme for (j = 0; j <1024; j ++) after this scheme is followed by the current element and operation) // sum = (sum + X [I-1] [J] * Y [I] [J]) % MOD; For (j = 0; j <1024; j ++) // pass the previous scheme to Y [I] [J] = (Y [I] [J] + Y [I + 1] [J]) % MOD ;} printf ("% i64d \ n", sum);} return 0 ;}

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.