HDU 4901 the Romantic Hero

Source: Internet
Author: User

The Romantic herotime limit:3000msmemory limit:131072kbthis problem would be judged onHDU. Original id:4901
64-bit integer IO format: %i64d Java class name: Main 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 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<=103, 0 <= a_i <1024, t<=20.OutputFor each test case, the output of the result in one line.Sample Input
231 2 341 2 3 3
Sample Output
1 4
SourceMulti-university Training Contest 4 Problem solving: Dynamic programming because of the existence of duplication, it is necessary to force the selection of the partition of the element, so there is dp[i][j][0] to represent the first I of the XOR and is J, and the number of options of the first I do not select Dp[i][j ][1] means the first I XOR and the number of schemes required for the first I (Dp2[i][j]) means that starting from I, followed by random selection of the number of solutions and J the answer is \[\sum_{i=1}^{n-1}\sum_{j=0}^{1023}dp[i][j][1]* Dp2[i+1][j]\]
1#include <bits/stdc++.h>2 usingLL =Long Long;3 using namespacestd;4 Const intMAXN =1010;5 ConstLL mod = 1e9 +7;6LL dp[maxn][1024x768][2],dp2[maxn][1024x768];7 intN,A[MAXN];8 intMain () {9     intKase;Tenscanf"%d",&Kase); One      while(kase--){ AMemset (DP,0,sizeofDP); -memset (DP2,0,sizeofDP2); -scanf"%d",&n); the          for(inti =1; I <= N; ++i) scanf ("%d", A +i); -dp[1][a[1]][1] =1; -          for(inti =2; I <= N; ++i) { -dp[i][a[i]][1]++; +              for(intj =0; J <1024x768; ++j) { -dp[i][j][0] + = dp[i-1][j][0] + dp[i-1][j][1]; +dp[i][j^a[i]][1] + = dp[i-1][j][0] + dp[i-1][j][1]; Adp[i][j][0] %=MoD; atdp[i][j^a[i]][1] %=MoD; -             } -         } -Dp2[n][a[n]] =1; -          for(inti = n1; i >0; --i) { -dp2[i][a[i]]++; in              for(intj =0; J <1024x768; ++j) { -DP2[I][J] + = dp2[i+1][j]; toDp2[i][j&a[i]] + = dp2[i+1][j]; +DP2[I][J]%=MoD; -Dp2[i][j&a[i]]%=MoD; the             } *         } $LL ret =0;Panax Notoginseng         for(inti =1; I < n; ++i) -          for(intj =0; J <1024x768; ++j) theRET = (ret + dp[i][j][1]*dp2[i+1][J])%MoD; +printf"%i64d\n", ret); A     } the     return 0; +}
View Code

HDU 4901 the Romantic Hero

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.